Error with using .find method 
Author Message
 Error with using .find method

Hi,

I have had "Invalid Procedure Call or Wrong Argument" error and sometimes
run-time memory errors when running the following VB code in Word 2000. It
has something to do with using '.ClearFormatting' and '.Text = ...'. But I
got the code from MS Word VB Sample codes. Can anybody help?

Thanks!

Yan

----------------------------------------------------------------------------
--------
Public Sub FindInSelectionExample()
    Dim strFindText   As String

    ActiveDocument.Content.Select

    With Selection.Find
       '.ClearFormatting
       'strFindText = InputBox("Enter the text you want to find.", _
       '   "Find Text")
       strFindText = "Radio"
       If Len(strFindText) = 0 Then Exit Sub
       .Text = strFindText
       'If .Execute = True Then
          MsgBox "'" & strFindText & "'" _
             & " was found and is now highlighted."
       'Else
       '   MsgBox "The text could not be located."
       'End If
    End With
End Sub



Mon, 24 May 2004 04:12:17 GMT  
 Error with using .find method
Hi, Yan.

I think you're asking a two-part question (1) How to code to obtain
the desired functionality and (2) applicability of examples published
by Microsoft.  

I probably can't help much with (1) (a question you've probably
already answered or had answered (but I can't resist - see below.):).

Re (2): Typographical errors in documentation is *always* a
possibility?  :)

Also Microsoft "help" is characteristically more mnemonic than
tutorial (meaning that learning is supposed to have already occurred
before consulting it).  The accuracy and completeness of MS-program
"help for users" isn't dependable except for some aspects of basic
functionality.  

Good luck,
ReMoore (Rachelle)

Quote:

>Hi,

>I have had "Invalid Procedure Call or Wrong Argument" error and sometimes
>run-time memory errors when running the following VB code in Word 2000. It
>has something to do with using '.ClearFormatting' and '.Text = ...'. But I
>got the code from MS Word VB Sample codes. Can anybody help?

>Thanks!

>Yan

(see annex below)
W i t h . . E n d  W i t h  doesn't appear to be a control structure
that has a corresponding  E x i t  action available. Likely the
compiler flags a possible ambiguity because (for instance)
W i t h   S e l e c t i o n . F i n d
        . T e x t = " w h a t e v e r "
        I f   . E x e c u t e   T h e n   E x i t   S u b
E n d   W i t h
is possible.  

In that case, the scope of  E x i t  could be
- the  S e l e c t i o n  object procedure
- the  W i t h . . E n d  W i t h  statement
- or the procedure containing it.

That's just a guess.  

s t a r t   a n n e x  
Public Sub FindInSelectionExample()
    Dim strFindText   As String

    ActiveDocument.Content.Select

    With Selection.Find
       '.ClearFormatting
       'strFindText = InputBox("Enter the text you want to find.", _
       '   "Find Text")
       strFindText = "Radio"
       If Len(strFindText) = 0 Then Exit Sub
       .Text = strFindText
       'If .Execute = True Then
          MsgBox "'" & strFindText & "'" _
             & " was found and is now highlighted."
       'Else
       '   MsgBox "The text could not be located."
       'End If
    End With
End Sub
e n d  a n n e x



Sun, 13 Jun 2004 05:47:53 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Error 405(Method not allowed) error in using webclient.uploadfile method

2. Please help - error using .Find method

3. Creating Items collection using Find method instead of Restrict

4. CDO Problem using the GetMessage method to find a message in a Public Folder

5. Using the FileOpen dialog to find a file to open so I can use ReadLine method

6. Using the find and findNext Methods with Like

7. Creating Items collection using Find method instead of Restrict

8. Using FIND method to get Exact match

9. using Find Method for Exact match

10. Error with Selection.Find method

11. Using CodeModule.Find method in Word VBE - help!

12. Compile Error: EndKey Method not found

 

 
Powered by phpBB® Forum Software