Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2006

Tip: Looking for answers? Try searching our database.

Change Pipe Character to Square Brackets Find Replace Loop

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rose - 24 Aug 2006 13:22 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.