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 / March 2005

Tip: Looking for answers? Try searching our database.

Macro-replacement of strings that have ["] in them

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Svendsen - 01 Mar 2005 00:05 GMT
Hi All,

Does anyone know how to get around the problem of replacing strings that
have ["] in them? As the delimiter is itself an ["], if there is an ["] in
the middle of strings the replace does not work.

Thanks a lot!!!
Jay Freedman - 01 Mar 2005 01:30 GMT
>Hi All,
>
[quoted text clipped - 3 lines]
>
>Thanks a lot!!!

Hi John,

You can use either two quotes together or the function Chr$(34), which
refers to the fact that the ASCII value of the quote character is 34.

As an example, to find the string

  Say "hello"

your macro might contain the code

  With Selection.Find
      .Text = "Say ""hello"""
    ' ...
  End With

or the code

  With Selection.Find
      .Text = "Say " & Chr$(34) & "hello" & Chr$(34)
    ' ...
  End With

If you're going to use this character a lot, you could define a
constant at the beginning of the macro and use that to save
keystrokes:

   Const vbQt = """"
   With Selection.Find
       .Text = "Say " & vbQt & "hello" & vbQt
    ' ...
  End With

--
Regards,
Jay Freedman
Microsoft Word MVP         FAQ: http://word.mvps.org
Jezebel - 01 Mar 2005 01:46 GMT
I'd also suggest that you construct the search string in a variable, if only
to make debugging simpler --

Dim pSearch as string

pSearch = "Say " & Chr$(34) & "hello" & Chr$(34)
Debug.Print "Searching for: " & pSearch

With Selection.Find
   .text = pSearch
   :

>>Hi All,
>>
[quoted text clipped - 41 lines]
> Jay Freedman
> Microsoft Word MVP         FAQ: http://word.mvps.org 
 
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.