#1
|
|||
|
|||
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 Code:
.Text = "START_KEYWORD^p(*)END_KEYWORD" Can someone help me, please? Alex |
#2
|
||||
|
||||
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
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 |
#4
|
|||
|
|||
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 |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
best way to use search/replace wildcards in this scenario? | dylansmith | PowerPoint | 3 | 03-04-2023 08:55 PM |
Search and replace wildcards | eduzs | Word VBA | 2 | 06-29-2019 03:01 AM |
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 |