Or_A
asked on
vb left function not working
hi,
i have vb sub under Excel, which returns this error: "Object doesnt support this property or method".
the code succesfully openes a word doc file, and cycles through each word in the doc.
i want to write a line saying: "if a word starts with the letters FLD then..."
but i keep getting this error message.
i tried using left and left$ (i dont know the difference but i saw the use of both), but both didnt work.
the code attached. can anyone tell me what i'm doing wrong?
thanks!
i have vb sub under Excel, which returns this error: "Object doesnt support this property or method".
the code succesfully openes a word doc file, and cycles through each word in the doc.
i want to write a line saying: "if a word starts with the letters FLD then..."
but i keep getting this error message.
i tried using left and left$ (i dont know the difference but i saw the use of both), but both didnt work.
the code attached. can anyone tell me what i'm doing wrong?
thanks!
Private Sub OK_Click()
'hide form
findProposal.Hide
Dim path$
'gets the path for the word file
path$ = findProposal.Label1
GetWordDoc (path$)
End Sub
Function GetWordDoc(strPath As String) As Boolean
Dim objDoc As Object, objRange As Object, objAppWord As Object
Dim strNewPath As String
Dim wks As Worksheet
Dim n As Long
Dim varLookup
On Error GoTo err_handle
GetWordDoc = True
Set wks = ActiveWorkbook.Sheets("MergeSheet")
Set objDoc = GetObject(strPath, "Word.Document")
Set objAppWord = objDoc.Application
For n = 1 To objDoc.Words.Count
'this is the problematic line:
If Left(objDoc.Words.Text, 3) = "FLD" Then
End If
nextn:
Next n
clean_up:
objDoc.Close
Exit Function
err_handle:
MsgBox Err.Description
GetWordDoc = False
Resume clean_up
End Function
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER