Or_A
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 :)
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks :)