Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-12-2018, 02:25 PM
jeffreybrown jeffreybrown is offline Pass a range to another macro to bold before em dash Windows Vista Pass a range to another macro to bold before em dash Office 2007
Expert
Pass a range to another macro to bold before em dash
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default 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
I would like to use the macro below to feed into the macro above, but I can't seem to figure out which parts should be excluded to make it run properly.

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
I know the construct should be...

Code:
Sub Bold_Terms(Rng As Range)
With Rng
…
End with
End Sub
Just having trouble understanding how to fit this into the For next statement.
Reply With Quote
  #2  
Old 09-12-2018, 03:30 PM
macropod's Avatar
macropod macropod is offline Pass a range to another macro to bold before em dash Windows 7 64bit Pass a range to another macro to bold before em dash Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 09-12-2018, 04:14 PM
jeffreybrown jeffreybrown is offline Pass a range to another macro to bold before em dash Windows Vista Pass a range to another macro to bold before em dash Office 2007
Expert
Pass a range to another macro to bold before em dash
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

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
Reply With Quote
Reply



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
Pass a range to another macro to bold before em dash Bold a sentence containing an em dash jeffreybrown Word 8 09-08-2016 05:47 PM
Pass a range to another macro to bold before em dash 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
Pass a range to another macro to bold before em dash Need Word to change -- (dash,dash) into one long dash. Bobosmite Word 2 05-06-2011 04:21 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:35 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft