#1
|
|||
|
|||
Pass a range to another macro to bold before em dash
This macro by itself works perfectly fine to bold everything before the em dash, but not to include the em dash. Below is one example, but basically it's everything between the two words, Terms and Attachment 2
Before Workload Factor—A measure of effort After Workload Factor—A measure of effort Code:
Sub Bold_Terms() Dim oPara As Paragraph Dim oRng As Range Dim oSel As Range Set oSel = Selection.Range For Each oPara In oSel.Paragraphs Set oRng = oPara.Range oRng.Collapse 1 'Em Dash (151) Comma (44) Space (32) oRng.MoveEndUntil Chr(151) oRng.Style = "Strong" oRng.Collapse 0 oSel.Select Next oPara lbl_Exit: Set oRng = Nothing Set oSel = Nothing Exit Sub End Sub Code:
Sub Find_Terms() With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "Terms*Attachment 2" .Replacement.Text = "" .Forward = True .Format = False .MatchWildcards = True .Wrap = wdFindStop .Execute End With If .Find.Found = True Then .Start = .Paragraphs.First.Range.End .End = .Paragraphs.Last.Range.Start Call Bold_Terms(.Duplicate) End If End With End Sub Code:
Sub Bold_Terms(Rng As Range) With Rng … End with End Sub |
#2
|
||||
|
||||
Perhaps:
Code:
Sub Demo() With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "^+" .Replacement.Text = "" .Forward = True .Format = False .MatchWildcards = False .Wrap = wdFindStop .Execute End With Do While .Find.Found = True With .Duplicate .Start = .Paragraphs.First.Range.Start .End = .End - 1 .Font.Bold = True End With .Collapse wdCollapseEnd .Find.Execute Loop End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thanks Paul. I added the loop and now it works fine.
Code:
Sub Bold_Terms(Rng As Range) With Rng With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "^+" .Replacement.Text = "" .Forward = True .Format = False .MatchWildcards = False .Wrap = wdFindStop .Execute End With Do While .Find.Found With .Duplicate .Start = .Paragraphs.First.Range.Start .End = .End - 1 .Font.Bold = True End With .Collapse wdCollapseEnd .Find.Execute Loop End With End Sub |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Two problems: Applying bold affects other tables and canvas doesn't appear at specified range | slaycock | Word VBA | 6 | 12-08-2016 02:28 AM |
Bold a sentence containing an em dash | jeffreybrown | Word | 8 | 09-08-2016 05:47 PM |
Reverse Bold macro | brent chadwick | Word VBA | 15 | 02-26-2016 05:25 PM |
Macro Needed to bold specific lines and Macro to turn into CSV | anewteacher | Word VBA | 1 | 05-28-2014 03:59 PM |
Need Word to change -- (dash,dash) into one long dash. | Bobosmite | Word | 2 | 05-06-2011 04:21 AM |