Stacey_Elaine
asked on
Compile Error: Function call on left-hand side of assignment must return Variant or Object
Have created a table in Access with list of .doc files from certain directory as my recordset, am using For-Next to open each document. This is working so far. I am needing to find and replace in the document, and am getting the compile error. PLEASE HELP!!
Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim WordRange As Word.Range
Set objWord = New Word.Application
With objWord
.Visible = True
Set objDoc = .Documents.Open(strFile, , False)
End With
Set WordRange = objDoc.Content
With WordRange.Find
.Execute(FindText:=strTrus t, REPLACEWITH:=Underscore, Replace:=Word.wdReplaceAll , Forward:=True) = True
End With
Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim WordRange As Word.Range
Set objWord = New Word.Application
With objWord
.Visible = True
Set objDoc = .Documents.Open(strFile, , False)
End With
Set WordRange = objDoc.Content
With WordRange.Find
.Execute(FindText:=strTrus
End With
Did you set a reference to WORD? It's a requirement to use the Word API.
Also, the ".execute" returns a boolean value so you must code for that.
something like this...
If .Execute(FindText:=strTrus t, REPLACEWITH:=Underscore, Replace:=Word.wdReplaceAll , Forward:=True) = True Then
End If
something like this...
If .Execute(FindText:=strTrus
End If
yeah, either do an IF statement or assign a value to the .execute statement.
blnVal = .Execute(FindText:=strTrus t, REPLACEWITH:=Underscore, Replace:=Word.wdReplaceAll , Forward:=True)
blnVal = .Execute(FindText:=strTrus
ASKER
then what would i do with the bInVal? i know i sound like a kindergartner here, but ALL i want is to open a document, find and replace text! i'm able to find text and format, but for some reason not replace text. i'm lost. and not, clearly, a programmer.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
blnVal worked! Thank you so much!!