Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Macro question
I am trying to get a macro that will highlight every paragraph that
begins with "Q:" (omit the quotation marks) and then italicize it. Can anyone help? * * * I have something like this but it doesn't work Sub Highlight() ' ' Highlight Macro ' Applies color highlighting to the selection ' WordBasic.Highlight Sub Tc() Selection.HomeKey wdStory With Selection.Find .Text = "Q:" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False Do While .Execute Selection.EndKey Unit:=wdLine, Extend:=wdExtend Selection.Font.Italic = True Selection.Collapse wdCollapseEnd Loop End With End Sub |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Macro question
If you are sure that the Q: only ever appears at the beginning of a
paragraph, you can use: Dim drange As Range Selection.HomeKey wdStory Selection.Find.ClearFormatting With Selection.Find Do While .Execute(FindText:="Q:", MatchWildcards:=False, Wrap:=wdFindStop, Forward:=True) = True Set drange = Selection.Paragraphs(1).Range drange.HighlightColorIndex = wdYellow drange.Font.Italic = True Loop End With If however the Q: might appear somewhere else in a paragraph and you do not want that paragraph changed, use the following, but in this case, it will not change the first paragraph in the document if that happens to start with Q: Dim drange As Range Selection.HomeKey wdStory Selection.Find.ClearFormatting With Selection.Find Do While .Execute(FindText:="^pQ:", MatchWildcards:=False, Wrap:=wdFindStop, Forward:=True) = True Set drange = Selection.Range drange.Start = drange.Start + 1 drange.End = drange.Paragraphs(1).Range.End drange.HighlightColorIndex = wdYellow drange.Font.Italic = True Loop End With -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP wrote in message oups.com... I am trying to get a macro that will highlight every paragraph that begins with "Q:" (omit the quotation marks) and then italicize it. Can anyone help? * * * I have something like this but it doesn't work Sub Highlight() ' ' Highlight Macro ' Applies color highlighting to the selection ' WordBasic.Highlight Sub Tc() Selection.HomeKey wdStory With Selection.Find .Text = "Q:" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False Do While .Execute Selection.EndKey Unit:=wdLine, Extend:=wdExtend Selection.Font.Italic = True Selection.Collapse wdCollapseEnd Loop End With End Sub |
#3
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Macro question
WOW! Thanks, it works and saved me alot of time
(PS there may be an error if someone just cuts and pastes it, be sure to not have an extra space on the main line (it will be in red if the macro fails to run) |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Features | Microsoft Word Help | |||
Macro execution using MailMerge | Mailmerge | |||
macro runs from keyboard, but not from macro button-why? | Microsoft Word Help | |||
Macro question | Microsoft Word Help | |||
FilePrint macro didn't work after all... | Microsoft Word Help |