Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-08-2021, 02:37 PM
jeffreybrown jeffreybrown is offline Replace paragraph with style and add an em dash Windows 10 Replace paragraph with style and add an em dash Office 2016
Expert
Replace paragraph with style and add an em dash
 
Join Date: Apr 2016
Posts: 639
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default Replace paragraph with style and add an em dash

I have many instances in my document like



MESSAGE NOTES Luke 3:16
MESSAGE NOTES Luke 9:15-19
MESSAGE NOTES Luke 21:15-19

I would like to make two changes.
1) Change the style to "Book Title" and
2) Add an em dash in-between MESSAGE NOTES and the next word.

The examples above, all end with a paragraph mark.

Code:
Sub Replace_Me()
    With ActiveDocument.Range.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Replacement.Style = ActiveDocument.Styles("Book Title")
        .Text = "MESSAGE NOTES Luke"
        .Replacement.Text = "^&"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute Replace:=wdReplaceAll
    End With
End Sub

Last edited by jeffreybrown; 05-08-2021 at 07:37 PM.
Reply With Quote
  #2  
Old 05-08-2021, 04:01 PM
jeffreybrown jeffreybrown is offline Replace paragraph with style and add an em dash Windows 10 Replace paragraph with style and add an em dash Office 2016
Expert
Replace paragraph with style and add an em dash
 
Join Date: Apr 2016
Posts: 639
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default

Figured it out with two macro. Since one of these macros uses FNR and the other does not, can they be combined or should they just stay separate?

Code:
Sub Replace_Me()
    With ActiveDocument.Range.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Replacement.Style = ActiveDocument.Styles("Book Title")
        .Text = "^13MESSAGE NOTES[!^13]@^13"
        .Replacement.Text = "^&"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = True
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute Replace:=wdReplaceAll
    End With
End Sub
Code:
Sub Macro5()
    With ActiveDocument.Range.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "DETAILED NOTES John"
        .Replacement.Text = "MESSAGE NOTES ^+ Luke"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
        .Execute Replace:=wdReplaceAll
    End With
End Sub

Last edited by jeffreybrown; 05-08-2021 at 07:36 PM.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does paragraph inherit style of the following paragraph? WADEVCAMP Word VBA 2 04-08-2019 02:13 PM
Find/Replace adds a style to what I'm searching for AND the following paragraph JFDI Word 2 03-27-2014 05:36 PM
Find bullets and replace with paragraph style? cdybdahl Word 1 12-02-2011 02:14 AM
Replace paragraph with style and add an em dash Need Word to change -- (dash,dash) into one long dash. Bobosmite Word 2 05-06-2011 04:21 AM
Character style stripped while applying paragraph style sams_gates Word 0 08-29-2009 02:03 AM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 01:56 AM.


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