Results 1 to 10 of 10
  1. #1
    Star Lounger
    Join Date
    Jan 2003
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Intermittent Word Find problem (Word XP)

    Hello. I have been puzzled lately because some of my macros which worked seemlessly in Word97 are now working intermittently. What I mean is that they sometimes don't finish properly, but then sometimes they do. I think the problem is with the Word Find.

    Is this a bug in Word?
    1. Using Ctrl+F in a word document, find a style (eg "Heading 1").
    2. Now click "No formatting" and the style disappears. So find some text in the document.
    3. Now, in the VBA editor, if you ask "?selection.find.style" it still thinks you are searching for "Heading 1".

    Is anyone else finding this? Could this cause problems....

    Thanks.

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Intermittent Word Find problem (Word XP)

    Have a look at Flush bad karma from Word's find facility after an unsuccessful wildcard search on the Word MVPs website. It is an article by Bill Coan with a macro to resolve an issue that may be at work here.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    Star Lounger
    Join Date
    Jan 2003
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Intermittent Word Find problem (Word XP)

    I already clear the find and replace parameters. There is no way that I can think of to clear the "selection.find.style" parameter. If you select "(no style)" as the style in the Find box, the macro records : selection.find.style = "". However, try to run that code and you get an error.

  4. #4
    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: Intermittent Word Find problem (Word XP)

    Yes, but if Selection.Find.Format = False, it shouldn't matter what Selection.Find.Style is set to, should it? I know you've found something about which Word is not being entirely logical, but I'm not sure it's really the root of your problem. It's so easy to have problems like forgetting to collapse the selection in the midst of multiple finds, that I think you might want to keep testing before returning to this particular issue.

  5. #5
    Star Lounger
    Join Date
    Jan 2003
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Intermittent Word Find problem (Word XP)

    Thanks. I will keep testing.

    There are 2 macros that worked perfectly in Word97, but now they only work sometimes. When I step through the code it always works. Also, if we run the macros a second time it usually works correctly. It is very hard to track down what is going wrong. The macros are quite simple. So I am looking for something (perhaps in the documents themselves) that is causing the problem.

    <img src=/S/confused.gif border=0 alt=confused width=15 height=20>

  6. #6
    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: Intermittent Word Find problem (Word XP)

    Are the macros something you can post? (In a zip file)

  7. #7
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Intermittent Word Find problem (Word XP)

    I had the same problem years ago. If I stepped through the macro there was no problem and if I ran it at speed the problem regularly came up.

    It was so long ago I am not sure how I solved it or why it hasn't bothered me since then. I think perhaps it is because I now more commonly use ranges rather than selection objects. Have you tried the same code using a range instead of a selection?

    It was a problem for me in Word 97 and nowdays I use both 97 and 2000 most regularly so I suspect that the problem is not version related.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  8. #8
    Star Lounger
    Join Date
    Jan 2003
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Intermittent Word Find problem (Word XP)

    Thanks Andrew. That is worth a try. We do use selection objects most of the time. Also, we have now got much faster computers and maybe the speed has something to do with it. I will rewrite it with the range object and let you know if that fixes the problem.

  9. #9
    Star Lounger
    Join Date
    Jan 2003
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Intermittent Word Find problem (Word XP)

    Thank you Jsher,

    Below is a sample of some code which used to work all the time. But if I run it again, or step through, then it always works. So speed could be the issue here. I will follow Andrew's suggestion to rewrite it with the range object and hope that will fix it.

    With Selection
    .MoveStart wdLine, 1
    lngCommStart = .Start
    Do
    If LCase(Left(.Paragraphs(1).Style, 7)) = "heading" Then
    bNextHeading = True
    .MoveUp wdParagraph, 1
    .Paragraphs(1).Range.Select
    .Collapse wdCollapseEnd
    Else
    If .Information(wdWithInTable) Then
    .Tables(1).Select
    End If
    .MoveDown wdParagraph, 1
    End If
    Loop Until bNextHeading Or .End = (ActiveDocument.Content.End - 1)
    lngCommEnd = .End
    .SetRange lngCommStart, lngCommEnd
    If lngCommEnd > lngCommStart Then
    .Copy
    f_CopyCommencementDetails = True
    End If
    End With

  10. #10
    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: Intermittent Word Find problem (Word XP)

    I think Guy Gallo or Klaus Linke posted some code that worked "between headers of a given level." This was many months ago, perhaps on the VBA board. Complicated stuff...

Posting Permissions

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