Answered by:
Need help with formatting a string

Question
-
I'm not overly experienced with scripting macros and need some help with something that has been stumping me all day. My code is similar to the following:
Sub thisStatement() Dim MyText As String MyText = "Use this date " & Format((Date + 90), "d/m/yy") Selection.TypeText (MyText) End Sub
What I want to do though is highlight the text in yellow and put a border around it so that when the sub is called, the statement is already formatted. Nothing I've tried has worked and I haven't been able to find any examples of something similar. Can anyone help? Thanks jhighland
Friday, July 9, 2010 2:57 AM
Answers
-
Use:
With Selection.Range
.Text = "Use this date " & Format((Date + 90), "d/m/yy")
.HighlightColorIndex = wdYellow
With .Borders
.OutsideLineStyle = wdLineStyleDoubleWavy 'or pick one of the other options.
.OutsideColor = wdColorBlack
End With
End With
-- Hope this helps.Doug Robbins - Word MVP,
dkr[atsymbol]mvps[dot]org
Posted via the Community Bridge"jhighland" wrote in message news:e61ca42d-ba05-4754-9c14-3b076bec0b17@communitybridge.codeplex.com...
I'm not overly experienced with scripting macros and need some help with something that has been stumping me all day. My code is similar to the following:
Sub thisStatement() Dim MyText As String MyText = "Use this date " & Format((Date + 90), "d/m/yy") Selection.TypeText (MyText) End Sub
What I want to do though is highlight the text in yellow and put a border around it so that when the sub is called, the statement is already formatted. Nothing I've tried has worked and I haven't been able to find any examples of something similar. Can anyone help? Thanks jhighland
Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org- Proposed as answer by Simon Jones [MSDL] Sunday, July 11, 2010 2:23 PM
- Marked as answer by Sally Tang Monday, July 12, 2010 8:07 AM
Friday, July 9, 2010 9:08 AM
All replies
-
You mean you want to add MyText to the current location in the file and highlight it and put a border around it? If so
Sub thisStatement()
Dim MyText As String
MyText = "Use this date " & Format((Date + 90), "d/m/yy")
Selection.TypeText (MyText)
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
Options.DefaultHighlightColorIndex = wdYellow
Selection.Range.HighlightColorIndex = wdYellow
With Selection.Font.Borders(1)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
End Sub
If this answer solves your problem, please check Mark as Answered. If this answer helps, please click the Vote as Helpful button. Cheers, Shane DevenshireFriday, July 9, 2010 3:31 AM -
Use:
With Selection.Range
.Text = "Use this date " & Format((Date + 90), "d/m/yy")
.HighlightColorIndex = wdYellow
With .Borders
.OutsideLineStyle = wdLineStyleDoubleWavy 'or pick one of the other options.
.OutsideColor = wdColorBlack
End With
End With
-- Hope this helps.Doug Robbins - Word MVP,
dkr[atsymbol]mvps[dot]org
Posted via the Community Bridge"jhighland" wrote in message news:e61ca42d-ba05-4754-9c14-3b076bec0b17@communitybridge.codeplex.com...
I'm not overly experienced with scripting macros and need some help with something that has been stumping me all day. My code is similar to the following:
Sub thisStatement() Dim MyText As String MyText = "Use this date " & Format((Date + 90), "d/m/yy") Selection.TypeText (MyText) End Sub
What I want to do though is highlight the text in yellow and put a border around it so that when the sub is called, the statement is already formatted. Nothing I've tried has worked and I haven't been able to find any examples of something similar. Can anyone help? Thanks jhighland
Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org- Proposed as answer by Simon Jones [MSDL] Sunday, July 11, 2010 2:23 PM
- Marked as answer by Sally Tang Monday, July 12, 2010 8:07 AM
Friday, July 9, 2010 9:08 AM -
Thank you for the solution - it worked perfectly!
Shane, thank you for your time as well.
jhighland
Saturday, July 10, 2010 12:51 PM