Results 1 to 12 of 12
  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

    FIND selection not changed? (WordXP)

    I'm using Selection.Find to locate paragraphs styled as "Normal".

    The Word XP help files (Find Object) state in part "If you've gotten to the Find object from the Selection object, the selection is changed when text matching the find criteria is found."
    My code is <pre>Sub FindingNormal()
    Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting
    Selection.Find.Style = ActiveDocument.Styles("Normal")
    With Selection.Find
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    If Selection.Find.Execute Then
    If Selection.Information(wdInHeaderFooter) Then
    Else
    MsgBox "Found a Normal style"
    End If
    Else
    End If
    End Sub
    </pre>


    The body of the document (attached) contains no Normal paragraphs; the footer of the document DOES contain Normal paragraphs.
    And yet still the MsgBox pops up!

    If I convert the table to Tab-delimited text, the program code works fine!

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #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: FIND selection not changed? (WordXP)

    Must be a bug. If you insert this before your "Am I in a footer" test--

    Debug.Print "Selection Start=" & Selection.Start & "; End=" & Selection.End

    --the result is--

    Selection Start=0; End=0

    --which seems wrong on many levels. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  4. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FIND selection not changed? (WordXP)

    > Must be a bug.
    In Microsoft Word? I thought we weren't allowed to say that in here (riffles through Rules .....).

    Thanks for the confirmation.
    I know I'm going crazy; that goes with having a cat.
    But sometimes I feel I'm going crazy when I'm doing something perfectly sane, such as VBA programming.

  5. #4
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: FIND selection not changed? (WordXP)

    I'm guessing <!post=this thread, 462724>this thread<!/post> addresses the problem you've encountered.

  6. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FIND selection not changed? (WordXP)

    > I'm guessing this thread addresses the problem you've encountered.

    Yes, Steve, it does. You pipped me to the post by 3 months! I had searched MSKB and come up empty. I thought it odd that I'd be the first in ANYthing in MSoft, especially finding a bug.

    >after which the 2nd execution delivered the knockout punch
    I interpret this as "the bug itself has a bug, and can't even fail properly"

    >make sure none of my documents ever have any "Normal" paragraphs
    This might have been tongue-in-cheek, but I am charged with eliminating all Normal styles from a set of 6,000+ documents. In desperation I inserted my crude test to trap any failures in my code, and, of course, even my simple test failed - on account of this bug.
    I found too some cases where a non-Normal paragraph containing ONLY a {TC} or {TOC} was reported as Normal, but I couldn't see any Normal in the TC/TOC. Possibly the same problem.

    Hans> You could check whether the range actually moves:
    Hans's suggestion has the most appeal, mainly because I've tried to shy away from Selection except for the user-interface. I'm not certain, though, that Range will make much difference; the problem appears to lie in the Find object.

    Andrew>your macro took 2:38, and the one below, just 9 seconds.
    I should question him on this; I expect Andrew's code to run faster because, well, it was written by Andrew. Do you think he got his text reversed here?

    Thanks again for the confirmation.
    I really do think sometimes I'm going insane faster than I ought, as in, "How can there be a bug in Find, after all this time? It must be something I'm doing wrong .....", and all this with a recorded macro!

  7. #6
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: FIND selection not changed? (WordXP)

    In case you're still looking for a workaround, have you tried testing if .Style = "Normal" (after the .Find.Execute) and using the .NextStoryRange method to jump to the start of the next story if it isn't?

  8. #7
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: FIND selection not changed? (WordXP)

    Or, rather, if you're using Selection.Find, I guess the Selection substitute for .NextStoryRange would be Selection.Move wdStory.

  9. #8
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FIND selection not changed? (WordXP)

    Thanks Steve. I couldn't get the wdStory to work, but this mod. seems to do what I (might) want:

    <pre> If Selection.Find.Execute Then
    If Selection.Style = "Normal" Then
    Else
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
    End If
    If Selection.Information(wdInHeaderFooter) Then
    Else
    MsgBox "Found a Normal style"
    End If
    Else
    End If</pre>


    "might" because I'm still pondering the significance of material in headers/footers for this project.

    Thanks again.

  10. #9
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: FIND selection not changed? (WordXP)

    Hmmm. You're right. It appears that Selection.Move wdStory just moves you to the end of the current story, rather than jumping to the next.

    I already had a function for moving a range to the next story (including to the first story of the next storytype if you're already in the last story of a particular type), so I've just adapted it for the Selection (attached). If you try it out and find any bugs, you're encouraged to let me know.

  11. #10
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FIND selection not changed? (WordXP)

    > so I've just adapted it for the Selection (attached).
    Thanks Steve, It looks good on the first try.
    It will get a real workout on the next batch of 6,000 documents.

    <pre>Sub FindingNormal()
    Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting
    Selection.Find.Style = ActiveDocument.Styles("Normal")
    With Selection.Find
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    If Selection.Find.Execute Then
    If Selection.Style = "Normal" Then
    MsgBox "Found a Normal style"
    Else
    While MoveSelection2NextStory
    If Selection.Style = "Normal" Then
    MsgBox "Found a Normal style"
    Exit Sub
    Else
    End If
    Wend
    End If

    Else
    End If
    End Sub
    </pre>


  12. #11
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: FIND selection not changed? (WordXP)

    I suspect that, after you MoveSelection2NextStory, you'll want to do another .Find.Execute, no? And then see if .Style = "Normal" at the next supposedly "found" target (rather than at the top of the story).

    It may be that all the features that trigger the bug (in my experience, end-of-row-markers, although it sounds like you may have found one or two others) are ones that would only appear in the main story. If that's the case you could cease the .Style = "Normal" testing once you'd done the first MoveSelection2NextStory (at which point, it would follow, MoveSelection2NextStory would never be triggered again...).

  13. #12
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: FIND selection not changed? (WordXP)

    > you'll want to do another .Find.Execute, no?
    In this case no. I was charged with eliminating all Normal styles. I achieved this, almost, with a mapping technique. Along the way, a few fractional font .Sizes and .Indents slipped through the net.

    I wrote the crude FindNormal as a final check to convince myself that no Normal styles remained in the document, which I treat as the wdMainStory. (Headers, Footers, Graphics, Protected docs etc are not part of the requirements). The bug alerted me to Normal styles in the header/footer, but the client isn't worried about those. I am worried because I'd like to say "There are no Normal styles in the MainStory", and felt that if ANY Normal style was found, I should be able to report that one was found, but that it was in the Header/Footer. The bug was thwarting my efforts to maintain control over what was found, and to rate its importance.

    >you could cease the .Style = "Normal" testing once you'd done the first MoveSelection2NextStory
    In the future, your (neat!) code will be useful. Who knows what the next requirements are? Maybe the bug will be fixed before I next need to scan for Normals; I doubt it. Your code is a welcome addition to my view of what can be achieved in VBA.

    For which I thank you, again!

Posting Permissions

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