Results 1 to 3 of 3
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    Sub testWL()
        With ThisDocument.VBProject.VBComponents(3).CodeModule
            Debug.Assert 18 = .CountOfLines ' Confirm we are looking at the correct module
            Dim lngStart As Long
            lngStart = -1
            While .Find("strFileTransient", lngStart, -1, -1, -1, True, False, False)
                Debug.Print lngStart
                lngStart = lngStart + 1
            Wend
        End With
    End Sub
    The attached document contains two code modules.
    The first code module contains the code posted above while the second code module contains code to be searched.
    Both the code above and the manual process of choosing (VBE) Edit, Find, WholeWord=True fail to locate the fourth occurrence of "strFileTransient" in the 2nd module.
    As in
    Code:
    FileName:=strFileTransient
    I have tested this on two WinXP machines, one running Word 2000, one running Word 2003
    Attached Files Attached Files

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You have specified True for the WholeWord argument of the Find method.

    Find is smart enough to know that commas and parentheses do not belong to a word, but apparently it considers the = before strFileTransient in FileName:=strFileTransient to belong to strFileTransient, so that it doesn't see this as an occurrence of the whole word.
    You can't change this behavior, so you should specify False for the WholeWord argument of Find and perform your own testing to determine whether it's the entire word (or perhaps you could use a regular expression).

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by HansV View Post
    ... perform your own testing to determine whether it's the entire word
    And my friends wonder why I have such a negative outlook on life ...
    Code:
      Option Explicit
    
    8        Dim strFileTransient As String
    9        strFileTransient = ThisDocument.Path & "\" & "Eraseme.JPG"
    10        Call modImages.ImageFileFromAscii(strFileTransient, sz)
    11        Selection.Range.InlineShapes.AddPicture FileName:=strFileTransient, LinkToFile:=True, SaveWithDocument:=True
    12        Call KillFile(ThisDocument, strFileTransient)
    13 '    Selection.Range.InlineShapes.AddPicture  strFileTransient, LinkToFile:=True, SaveWithDocument:=True
    14 '    Selection.Range.InlineShapes.AddPictu=strFileTransient, LinkToFile:=True, SaveWithDocument:=True
    15 '    SelectionRange=strFileTransient, LinkToFile:=True, SaveWithDocument:=True
    Line 15 (of the now-modified procedure) tells me something; as-is "strFileTransient" is not detected by the .Find, but with a space either side, as inserted by the little formatting-adjustment mechanism that kicks in when we leave a line, "strFileTransient' is detected.
    I am inclined to put this down as another design flaw; something that wasn't properly thought out before coding started.

    I've been trying to think of an instance when the current behavior might be useful, and can't dream one up.
    To the right of the ":=" must always be a reserved word or a user-identifier or constant.
    I can't think of a time when one might want NOT to find a reserved word or a user-identifier or constant.

Posting Permissions

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