![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Microsoft Office support MS Office support forum |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Registered User
Join Date: May 2009
Location: Ohio
Posts: 3
OS: XP
|
In the "good old" days, macros just recorded your keystrokes. Not so any more.
I need to help with a macro that will work on selected text. I want to select the text. Then, when I run the macro, a left bracket will be put at the beginning of the text I selected, a right bracket will be put at the end of the text I selected, and all (including the brackets) will be highlighted in a particular color, with the cursor ending up at the right of the closing bracket. I vaguely imaging some version of with. and end with needs to be used but that's about as much as I know. |
|
|
|
| Important Information |
|
Join the #1 Tech Support Forum Today - It's Totally Free!
TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free. Join TechSupportforum.com Today - Click Here |
|
|
#2 (permalink) |
|
TSF Enthusiast
Join Date: Apr 2008
Location: Australia
Posts: 570
OS: Vista
|
Re: Selected text - macro help
Hi Jeff,
What you're asking is really rather basic, and could be gleaned from a simple web search or any half-decent book on macros. Anyway, FWIW: Code:
Sub Demo()
Selection.InsertBefore "("
Selection.InsertAfter ")"
Selection.Font.Color = wdColorAqua
Selection.Collapse wdCollapseEnd
End Sub
Code:
Sub Demo()
With Selection
.InsertBefore "("
.InsertAfter ")"
.Font.Color = wdColorAqua
.Collapse wdCollapseEnd
End With
End Sub
__________________
Cheers macropod (MS MVP -Word) |
|
|
|
|
|
#3 (permalink) |
|
Registered User
Join Date: May 2009
Location: Ohio
Posts: 3
OS: XP
|
I do realize that what I was asking was basic - searching the 'net brought me to the great folks here. In any case, it turns out that what I needed was either of these (apply highlight color rather than font color). Note, the added spaces between the right bracket and the closing quote should not be there. The BBS software here is inserting them for some reason.
Code:
Sub HighlightSelectedText()
Selection.InsertBefore "["
Selection.InsertAfter "] "
Selection.Range.HighlightColorIndex = wdTurquoise
Selection.Collapse wdCollapseEnd
End Sub
'
'or
'
Sub HighlightSelectedText()
With Selection
.InsertBefore "["
.InsertAfter "] "
.Range.HighlightColorIndex = wdTurquoise
.Collapse wdCollapseEnd
End With
End Sub
Last edited by jeffdavis; 06-01-2009 at 11:56 AM. |
|
|
|
![]() |
| Thread Tools | |
|
|