![]() |
|
#1
|
|||
|
|||
![]()
# is space
Case in Find (—; —#; #—; ##—##; —##; ##—; etc...) Case in Change and Highlight (#—#) |
#2
|
||||
|
||||
![]()
You can do the lot with just two wildcard Find/Replace operations:
Find = — Replace = ^32—^32 and: Find = [ ]{1,}—[ ]{1,} Replace = ^32—^32
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]() Code:
Sub EmDash() Dim rngStory As Range For Each rngStory In ActiveDocument.StoryRanges Dim MyList() As String Dim i As Long Options.DefaultHighlightColorIndex = wdTurquoise MyList = Split("—,[ ]{1,}—[ ]{1,}") For i = 0 To UBound(MyList()) Set r = ActiveDocument.Range With rngStory.Find .Text = MyList(i) .Replacement.Text = "^32—^32" .MatchWildcards = True .MatchCase = True .Replacement.Highlight = wdTurquoise .Execute Replace:=wdReplaceAll End With Next Next End Sub Last edited by macropod; 05-29-2022 at 06:57 AM. Reason: Added code tags |
#4
|
||||
|
||||
![]()
I think you need to take another look at my reply in: https://www.msofficeforums.com/word-...e-i-tried.html
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
![]()
Ok i will check that for stories.
but can check where i mistake in the below code. Sub EmDash() Dim rngStory As Range For Each rngStory In ActiveDocument.StoryRanges Dim MyList() As String Dim i As Long Options.DefaultHighlightColorIndex = wdTurquoise MyList = Split("—,[ ]{1,}—[ ]{1,}") For i = 0 To UBound(MyList()) Set r = ActiveDocument.Range With rngStory.Find .Text = MyList(i) .Replacement.Text = "^32—^32" .MatchWildcards = True .MatchCase = True .Replacement.Highlight = wdTurquoise .Execute Replace:=wdReplaceAll End With Next Next End Sub |
#6
|
||||
|
||||
![]()
Kindly use code tags when posting code. You might at least also examine the code I posted in the link referred to instead of re-posting the same erroneous code you already posted.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
![]()
I think got now.
Sub Test() Dim i As Long, NameOrig As Variant MyList = Array("—", "[ ]{1,}—", "—[ ]{1,}", "[ ]{1,}—[ ]{1,}") Options.DefaultHighlightColorIndex = wdTurquoise With ActiveDocument.Range.Find .ClearFormatting .Replacement.ClearFormatting .Forward = True .Wrap = wdFindContinue .MatchWildcards = True .Replacement.Text = "^32—^32" For i = 0 To UBound(MyList) .Text = MyList(i) .Replacement.Highlight = wdTurquoise .Execute Replace:=wdReplaceAll Next End With End Sub |
#8
|
||||
|
||||
![]()
How often do you need to be reminded to use code tags when posting code?
As for the code you posted, it does not loop through all StoryRanges! Moreover, your array and loop are pointless - you really should pay attention to post #2...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
![]()
Kindly help me on this.
|
#10
|
||||
|
||||
![]()
I have already given you the only two F/R expressions you need and pointed you to my reply in https://www.msofficeforums.com/word-...e-i-tried.html. That is more than enough.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
alex100 | Word VBA | 2 | 05-04-2020 11:19 PM |
Find % change from last month automatically updated | GraemeSS | Excel | 7 | 04-03-2020 02:50 AM |
Loop through all shapes in all stories not working | Peterson | Word VBA | 5 | 03-04-2018 11:02 AM |
![]() |
Cosmo | Word | 1 | 06-19-2014 01:09 PM |
![]() |
Ssendam | Excel | 1 | 07-16-2009 11:44 AM |