Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-27-2022, 11:54 PM
stky stky is offline can find and change in all stories Windows 10 can find and change in all stories Office 2013
Advanced Beginner
can find and change in all stories
 
Join Date: Apr 2021
Posts: 30
stky is on a distinguished road
Default can find and change in all stories

# is space



Case in Find (—; —#; #—; ##—##; —##; ##—; etc...)

Case in Change and Highlight (#—#)
Reply With Quote
  #2  
Old 05-28-2022, 03:58 PM
macropod's Avatar
macropod macropod is offline can find and change in all stories Windows 10 can find and change in all stories Office 2016
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

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]
Reply With Quote
  #3  
Old 05-28-2022, 08:37 PM
stky stky is offline can find and change in all stories Windows 10 can find and change in all stories Office 2013
Advanced Beginner
can find and change in all stories
 
Join Date: Apr 2021
Posts: 30
stky is on a distinguished road
Default can we do or not like this method but I fail

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
Reply With Quote
  #4  
Old 05-29-2022, 07:00 AM
macropod's Avatar
macropod macropod is offline can find and change in all stories Windows 10 can find and change in all stories Office 2016
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

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]
Reply With Quote
  #5  
Old 05-29-2022, 07:10 AM
stky stky is offline can find and change in all stories Windows 10 can find and change in all stories Office 2013
Advanced Beginner
can find and change in all stories
 
Join Date: Apr 2021
Posts: 30
stky is on a distinguished road
Default

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
Reply With Quote
  #6  
Old 05-29-2022, 07:46 AM
macropod's Avatar
macropod macropod is offline can find and change in all stories Windows 10 can find and change in all stories Office 2016
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

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]
Reply With Quote
  #7  
Old 05-30-2022, 06:08 AM
stky stky is offline can find and change in all stories Windows 10 can find and change in all stories Office 2013
Advanced Beginner
can find and change in all stories
 
Join Date: Apr 2021
Posts: 30
stky is on a distinguished road
Default Thanks Macropod

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
Reply With Quote
  #8  
Old 05-31-2022, 07:29 AM
macropod's Avatar
macropod macropod is offline can find and change in all stories Windows 10 can find and change in all stories Office 2016
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

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]
Reply With Quote
  #9  
Old 05-31-2022, 09:04 PM
stky stky is offline can find and change in all stories Windows 10 can find and change in all stories Office 2013
Advanced Beginner
can find and change in all stories
 
Join Date: Apr 2021
Posts: 30
stky is on a distinguished road
Default Yes i fail to complete in this.

Kindly help me on this.
Reply With Quote
  #10  
Old 06-01-2022, 06:46 AM
macropod's Avatar
macropod macropod is offline can find and change in all stories Windows 10 can find and change in all stories Office 2016
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

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
can find and change in all stories Find and change the background color of certain keywords 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
can find and change in all stories Can a word doc have 2 continuous 'stories' across multiple pages? Cosmo Word 1 06-19-2014 01:09 PM
can find and change in all stories Find and Replace - Variable change Ssendam Excel 1 07-16-2009 11:44 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:11 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