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
Stacey_ElaineAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

carsRSTCommented:
Did you set a reference to WORD?  It's a requirement to use the Word API.
0
carsRSTCommented:
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
0
carsRSTCommented:
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)
0
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

Stacey_ElaineAuthor Commented:
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.
0
carsRSTCommented:
Since the execute statement returns a value (true/false), it's expecting you to evaluate it.

Honestly, you don't have to do anything with "blnVal".  Just put it there so you can execute the code.

you could, if you wanted, trap and see if anything was replaced and write code to handle hit.  But not necessary for your purposes.  True would mean it replaced; false would mean no replace.  

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Stacey_ElaineAuthor Commented:
blnVal worked! Thank you so much!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.