Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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
 



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 06:10 AM.


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