Link to home
Start Free TrialLog in
Avatar of Or_A
Or_AFlag for Israel

asked on

Error MSG: 'method text of object range failed'

hi,

i have a VB function under excel, with it i'm controling a word file (using late binding). the part of my code which im attaching is supposed to replace each word in the word file that starts with "FLD" with a word which the vlookup function finds in the excel.

strangly, the code works great on other computers, but on mine it failes (look at the snippet to see where i get the problem). because of that, i thought i have some bugs in my comp, so i formatted it and reinstalled Win XP and Office '03, but the problem remained.

can anyone see where is my problem?

thanks :)
Function GetWordDoc(strPath As String) As Boolean
 
'opens MSWORD and then the file
    Dim Wks As Worksheet
    Dim Objdoc As Object
    GetWordDoc = True
    Set Wks = ActiveWorkbook.Sheets("MergeSheet")
    Set Objdoc = GetObject(strPath, "Word.Document")
 
'replaces the fields
    Dim ends As String
    Dim VarLookup
    For Each Word In Objdoc.words
    If Trim$(Left$(Word.Text, 3)) = "FLD" Then
        VarLookup = Application.VLookup(Trim$(Word.Text), Wks.Range("B3:C600"), 2, False)
        If IsError(VarLookup) Then
            Word.Text = vbNullString
        Else
            Word.Text = VarLookup 'Here i get the Error - "Method Text of object Range Failed"
        End If
    End If
Next Word
 
End Function

Open in new window

SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Or_A

ASKER

i dont know why, but when i added 'on error goto next' it worked fine and it made the replacements perfect. so for this time, i'm satisfied with this, but in the future i'll make efforts to learn this early/late binding methods...  
thanks :)