Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Nottingham, UK, Nottinghamshire, England
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA in Excel using Word (Office 2000)

    A VBA procedure I wrote some time ago contains the following code. It's actually in an Excel module, but it's manipulating a Word document.

    With objWd.Selection.Find
    .MatchWildcards = True
    .Text = "!E?LIB"
    .Replacement.Text = "!E0LIB"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    objWd.Selection.Find.Execute Replace:=wdReplaceAll

    I understand it all - EXCEPT for the back-slash () at the beginning of the Text argument. I must have put it in for a reason, but for the life of me I cannot find any mention of this particular thing anywhere, in Help files or anywhere else. Yet it seems to work here, and in other places too. Can anyone enlighten me as to just what this back-slash achieves? I must have had a reason to put it in! Thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: VBA in Excel using Word (Office 2000)

    In searching with wildcards, the exclamation mark ! has a special meaning, you can use it to exclude certain characters from the search. For example, [!a-d] means any character except a, b, c, or d. If you want to include an exclamation mark in a wildcard search string, you must precede it with a backslash to indicate that it is a literal character, not a search modifier. So the search string "!E?LIB" means: search for !E followed by any character followed by LIB. Without the backslash, you'd get an error message. In the replace string, you can't use wildcards, so the backslash is not necessary there.

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Nottingham, UK, Nottinghamshire, England
    Posts
    190
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA in Excel using Word (Office 2000)

    Yes, of course!!! Now I remember! I thought it had to be something simple (not to mention stupid of me to forget), and it was. So obvious when it's pointed out. That's exactly what it is - I'm ensuring that the exclamation mark is included in the Find string. Thanks, Hans, especially for such a quick reply. Much appreciated. Now, if I can only reduce the number of senior moments ..........

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •