Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Jul 2002
    Location
    Wellington, New Zealand
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Inconsistancies with find/replace (Word 2000 SR1)

    I am trying to solve an odd issue in a template using Selection.Find

    The template is used to customise loan documents and runs as a wizard
    It uses loads of wordbasic code which is being updated as time and $$ allow
    Data is stored as document variables
    ini files are used through out
    it allows the user to reopen and re run the wizard
    It does this by adding a new document based on the template using the previous documents variables

    Now the problem

    The following code is part of a larger proc and is meant to replace a series of elements ( this is a series of strings that match the output from a different system) with the user input. The problem originally surfaced with code office updated itself ( wordbasic.etc) .In an attempt to solve the problem I have updated it to VBA as follows


    With Selection
    .HomeKey (wdStory)
    With .Find
    .MatchCase = False
    .MatchWholeWord = False 'making sure re the L later
    .ClearFormatting
    .Forward = True
    .MatchWildcards = True
    .Execute findtext:="@*." 'selects the first element elements begin with "@X" and end with "."
    Var_$ = Selection Populates the variable with the whole element inc the bits between the "@X" & "."
    While .Found
    AddDocVar (Var_$) 'function that goes to an ini file and grabs the variable name that matches
    'the element name ( the bit between the "@X" & ".") , replaces the selected
    ' text with the contents of the document variable.
    .Execute findtext:="@*." 'selects subsequent elements
    Var_$ = Selection
    Wend
    End With
    End With

    What happens is that the first time the wizard is run it works fine creating a new doc say DocName.doc
    If the wizard is again run from scratch the new document is fine lets call it DocName2.doc
    If the wizard is again run from DocName.doc the elements are not replaced
    If the wizard is run from DocName2 the elements are not replaced
    If the wizard is run from scratch the elements are not replaced.
    Once the elements are not replaced word must be shut down

    But if Word is closed and opened then it all begins again...but not for documents its previously failed on.

    In testing it seems that when the code runs ,but fails it is because no instances are found and Var_$ is populated by the letter L which is the first letter of the document. It of course can't be referenced in the ini file so the elements aren't replaced..., the interesting thing is that the .Found = false even though there are obviously a few L's in the document.


    But if I break and <alt><tab> to the document and click anywhere then return and <F8> from selection.homekey then the insertion point moves from anywhere to beginning of document. Also querying activedocument.name backs up the fact that I am working with the correct document.


    I have not attached the template because it is huge and references to other templates required for some functionality.

    I possible I would like to know why its happening as well as how to fix it

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Inconsistancies with find/replace (Word 2000 SR1)

    There is a line in here that doesn't seem right:

    Var_$ = Selection Populates the variable with the whole element inc the bits between the "@X" & "."

    For the sake of good order, I'd change it to this:

    Var_$ = Selection.Text ' Populates the variable with the whole element inc the bits between the "@X" & "."

    But there's really nothing wrong with this part of the code, from what I can see. Are you using a lot of public variables to move data between forms and modules? These values might be hanging around causing problems on subsequent iterations of the macro.

    Have you turned off error messages anywhere (e.g., On Error Resume Next)? Maybe something like a file open error on the INI file is being suppressed?

  3. #3
    Lounger
    Join Date
    Jul 2002
    Location
    Wellington, New Zealand
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Inconsistancies with find/replace (Word 2000 SR1)

    Yes there are a lot of public variables and this template is the startup template for word. I guess I know what I'm doing now

    Thanks

Posting Permissions

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