Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-16-2020, 04:06 AM
alex100 alex100 is offline Search and replace, with paragraphs and wildcards Windows 7 64bit Search and replace, with paragraphs and wildcards Office 2016
Novice
Search and replace, with paragraphs and wildcards
 
Join Date: May 2020
Posts: 29
alex100 is on a distinguished road
Default Search and replace, with paragraphs and wildcards

I need to remove all the text between two keywords. So far I have been using this code:



Code:
With Selection
    .HomeKey Unit:=wdStory
    With Selection.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "START_KEYWORD(*)END_KEYWORD"
    .MatchWildcards = True
    .Replacement.Text = ""
    .Execute Replace:=wdReplaceAll
    End With
End With
Now I need the search function to include paragraphs too, like this...

Code:
.Text = "START_KEYWORD^p(*)END_KEYWORD"
The problem is that, in such cases, the script no longer works.

Can someone help me, please?

Alex
Reply With Quote
  #2  
Old 05-16-2020, 06:24 AM
gmayor's Avatar
gmayor gmayor is offline Search and replace, with paragraphs and wildcards Windows 10 Search and replace, with paragraphs and wildcards Office 2016
Expert
 
Join Date: Aug 2014
Posts: 3,155
gmayor is a glorious beacon of lightgmayor is a glorious beacon of lightgmayor is a glorious beacon of lightgmayor is a glorious beacon of lightgmayor is a glorious beacon of lightgmayor is a glorious beacon of light
Default

You can't use ^p with the wildcard option. Use ^13 instead.


See Replace using wildcards
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 05-16-2020, 06:58 AM
gmaxey gmaxey is offline Search and replace, with paragraphs and wildcards Windows 10 Search and replace, with paragraphs and wildcards Office 2016
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 1,034
gmaxey will become famous soon enoughgmaxey will become famous soon enough
Default

The find string you are currently using already "finds" paragraph marks. If what you tried to do worked, it would only find the starting keyword if it occurs at the end of a paragraph. Is that what you want?


Code:
Sub ScratchMacro()
  'A basic Word macro coded by Greg Maxey
  With Selection
    .HomeKey Unit:=wdStory
     With Selection.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = "Start_Word" & Chr(13) & "(*)End_Word"
      .MatchWildcards = True
      .Replacement.Text = ""
      .Execute Replace:=wdReplaceAll
    End With
  End With
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #4  
Old 05-16-2020, 08:43 AM
alex100 alex100 is offline Search and replace, with paragraphs and wildcards Windows 7 64bit Search and replace, with paragraphs and wildcards Office 2016
Novice
Search and replace, with paragraphs and wildcards
 
Join Date: May 2020
Posts: 29
alex100 is on a distinguished road
Default

The starting keyword was actually a "|" sign, which was followed by a paragraph mark. These two symbols were the only ones on the line. What I needed to do was to delete all the text between these and another word (the ending keyword).

Anyhow, using Chr(13) instead of ^p worked great!

Graham, Greg - thank you both!

Alex
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Search and replace, with paragraphs and wildcards best way to use search/replace wildcards in this scenario? dylansmith PowerPoint 2 07-13-2019 07:06 AM
Search and replace, with paragraphs and wildcards Search and replace wildcards eduzs Word VBA 2 06-29-2019 03:01 AM
Search and replace, with paragraphs and wildcards Need Search and Replace Help w Wildcards Oberstfunster Word 2 12-06-2018 09:28 AM
Wildcards used for Search and Replace ChrisRick Word 2 03-09-2017 05:01 AM
Any wildcards search and replace in Powerpoint 2010? tinfanide PowerPoint 0 09-10-2011 02:17 AM

Other Forums: Access Forums - Senior Forums

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


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