Link to home
Start Free TrialLog in
Avatar of Stacey_Elaine
Stacey_ElaineFlag for United States of America

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:=strTrust, REPLACEWITH:=Underscore, Replace:=Word.wdReplaceAll, Forward:=True) = True
End With
Avatar of carsRST
carsRST
Flag of United States of America image

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:=strTrust, REPLACEWITH:=Underscore, Replace:=Word.wdReplaceAll, Forward:=True) = True Then
   
    End If
yeah, either do an IF statement or assign a value to the .execute statement.

blnVal = .Execute(FindText:=strTrust, REPLACEWITH:=Underscore, Replace:=Word.wdReplaceAll, Forward:=True)
Avatar of Stacey_Elaine

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
Avatar of carsRST
carsRST
Flag of United States of America 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
blnVal worked! Thank you so much!!