Results 1 to 2 of 2
  1. #1
    Lounger
    Join Date
    Apr 2002
    Location
    Sydney, Australia
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Search using Range fails (Word 2002, VBA)

    I use the following code to check if the word 'enclosure' appears in the current section:

    If modSharedCode.Encl = True Then
    Selection.InsertParagraph
    Selection.InsertParagraph
    Selection.TypeText "Enclosure"
    Selection.InsertParagraph
    End If
    GoTo startsearch

    Function Encl() As Boolean
    Dim intSection As Integer
    Dim rngDoc As Range

    intSection = Selection.Information(wdActiveEndSectionNumber)
    Set rngDoc = ActiveDocument.Sections(intSection).Range


    rngDoc.Find.ClearFormatting
    rngDoc.Find.Replacement.ClearFormatting
    With rngDoc.Find
    .Text = "enclos"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    End With
    If rngDoc.Find.Execute = True Then
    Encl = True
    Else
    Encl = False
    End If
    set rngDoc=Nothing
    Exit Function

    The next time my code performs a search using the standard Selection object, Word 2002 hangs and causes problems until I reboot the PC. I have experienced similar problems using the range object in other code. Does anyone know why? Is this a bug?

    Thanks

  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: Search using Range fails (Word 2002, VBA)

    Please reply in the duplicate thread on the Word board.

Posting Permissions

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