Search For String And Print

  • Re: Search For String And Print

    See that was my first intial thought. Well I cleaned up the to include only the code needed for the W5WW & W6WW. I'll test tomorrow again and see if the "rouge code" is gone.

  • Re: Search For String And Print

    I cleaned up the code a bit and restarted the computer and tried opening word docs and all was fine. No error messages as described in my prior post. So I thought, ok lets test the macro and again all was fine. But I tried opening an entirely different word doc after the macro was run and both those error messages came up.

    Any idea what the problem could be with the macro? Code has been attached.

  • Re: Search For String And Print

    The funny part about this is now it works. But later today, I'll get those same error messages. Not sure what to think about this anymore....

  • Re: Search For String And Print

    So what caused the problem to stop? Does rebooting the pc clear the problem, in which case there could be something running that is not visible that cause the problem.

    If a reboot does clear the problem then comment out all the code in the macro and then in a controlled methodical way uncomment lines and see if the problem returns. This way you can isolate the offending code and or event.

    Just curious though, you said this was in your, yes? If so how are you going to supply it to the other users?

  • Re: Search For String And Print

    Well this morning I didn't reboot my PC and its working. It wasn't working as of yesterday at 4:30 and it seems like some resets over night or during the reboot to cause things to work again.

    Awww what a nightmare of a macro.

  • Re: Search For String And Print

    Got a slight problem. Seems as though when one my the users ran this, they got unexpected results. In this case, the W5WW or W6WW will be on the 2nd page of the record, in most case it'll be on the 1st page.

    I've done some testing and can't seem to find a way around this.

    Help would be appreciated. Attached is the current code and word doc showing the bug.

  • Re: Search For String And Print

    It looks like the problem is that W6WW is not found BUT the second part of the find is 1101...5

    trouble is that it is related to the W5WW find and should be ignored.

    Perhaps you should store the previous find pages and check to make sure the next found pages is greater than previous.

  • Re: Search For String And Print

    Well how about not searching for the end item if the first search string is not found.
    [vba]Function MyFind(MyDoc As Document, FirstItem As String, EndItem As String) As String

    Dim strPage As String

    With Selection.Find
    .Text = FirstItem
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    If Selection.Find.Found Then
    strPage = CStr(Selection.Range.Information(wdActiveEndAdjustedPageNumber)) & "-"

    Exit Function ' Not found so quit
    End If

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!