Hi Justme,
I need to know how I can search a whole document to replace every \^p
(backslash and paragraph return), EXCEPT if it is immediately followed by 5
numbers, 1 letter, and a pipe character (|).
Is this possible?
Thank you.
Another way to do things would be to hide or mark characters in the first
Find(s) and Replace(s) that you don't want to find in the subsequent Find(s)
and Replace(s). Depending on the document layout this method might be
faster. For example:
Dim aR As Range
Set aR = ActiveDocument.Content
With aR.Find
.MatchWildcards = True
.Text = "\\^13[0-9]{5}[a-zA-Z]|" 'use \n for ^13 in MacWord
.Replacement.Text = "^&"
.Replacement.Font.hidden = True
.Execute replace:=wdReplaceAll
.Font.hidden = False
.Replacement.Font.hidden = False
.Text = "\\^13"
.Replacement.Text = "XXXX^&" 'for example
.Execute replace:=wdReplaceAll
End With
ActiveDocument.Content.Font.hidden = False
Hiding things is also good for exposing only a particular random-positioned
pattern in all paragraphs that you want to do a paragraph sort on.
First hide everything.
Second expose sort pattern.
After sorting then unhide everything.
For example:
Dim show_hide As Boolean
show_hide = ActiveWindow.ActivePane.View.ShowAll
ActiveWindow.ActivePane.View.ShowAll = True
ActiveDocument.Range.Font.hidden = True 'hide everything
Dim aR As Range
Set aR = ActiveDocument.Content
With aR.Find
.MatchWildcards = True
.Text = "XXXXXXX" 'sort pattern exposure
.Replacement.Text = "^&"
.Font.hidden = True
.Replacement.Font.hidden = False
.Execute replace:=wdReplaceAll
End With
ActiveWindow.ActivePane.View.ShowAll = False
ActiveDocument.Range.Sort ExcludeHeader:=False, FieldNumber:="Paragraphs", _
SortFieldType:=wdSortFieldNumeric, SortOrder:=wdSortOrderAscending
ActiveDocument.Range.Font.hidden = False
ActiveWindow.ActivePane.View.ShowAll = show_hide
A direct paragraph sort crashes a Word 97 computer at work. One way to get
around the crash on that computer is to convert the paragraphs into a table
and sort the table, then convert the sorted table back into paragraphs.
Which can be done via VBA within the subroutine.
Try
ActiveDocument.Range.TextRetrievalMode.IncludeHiddenText = False
If hidden text is not ignored during Find and Replace.