How do I replace Pipe |NAME| character with [NAME] square brackets in below
macro:
Stuck!
Option Explicit
Public Sub FindReplacePipe()
'Find replace [ ]
Dim replacement As String
replacement = InputBox("Enter the replacement text", "Replacer")
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="|[A-z]{1,}|", ReplaceWith:=replacement,
MatchWildcards:=True, Wrap:=wdFindContinue, Forward:=True) = True
Loop
End With
End Sub
Tony Jollans - 24 Aug 2006 13:59 GMT
I'm not entirely sure what you're asking but to find square brackets in a
wildcard search you need to escape them ...
FindText:="\[[A-z]{1,}\]"
Or are you asking how to change pipes to square brackets in the document at
the same time as your other change? In that case, try this ...
FindText:="|[A-z]{1,}|", ReplaceWith:="[" & replacement & "]"
Or have I completely missed the point?
--
Enjoy,
Tony
> How do I replace Pipe |NAME| character with [NAME] square brackets in below
> macro:
[quoted text clipped - 16 lines]
>
> End Sub
Dave Lett - 24 Aug 2006 14:10 GMT
You were close:
Dim sReplace As String
sReplace = InputBox("Enter the replacement text", "Replacer")
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.ClearFormatting
.Text = "|([A-z]{1,})|"
.MatchWildcards = True
.Wrap = wdFindContinue
.Forward = True
With .replacement
.ClearFormatting
.Text = sReplace & "\1" & sReplace
End With
.Execute Replace:=wdReplaceAll
End With
However, sReplace (I changed this from "replacement" because "Replacement"
is actually a parameter in the Find process) doesn't work the way you
probably want it to. Therefore, you will probably want to hard code the
replacement character, as in the following:
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
.ClearFormatting
.Text = "|([A-z]{1,})|"
.MatchWildcards = True
.Wrap = wdFindContinue
.Forward = True
With .replacement
.ClearFormatting
.Text = "[\1]" End With
.Execute Replace:=wdReplaceAll
End With
HTH,
Dave
> How do I replace Pipe |NAME| character with [NAME] square brackets in
> below macro:
[quoted text clipped - 16 lines]
>
> End Sub
Rose - 24 Aug 2006 14:20 GMT
Yes but close just doesn't work - MANY tks
> You were close:
>
[quoted text clipped - 57 lines]
>>
>> End Sub