Replacing text in Word Doc.
I am replacing text in a word document and it is working fine except in my 'If Then-End If' statement. I can not figure out why it isn't working, so I thought I would ask for some help. I have left out all the declarations and other code so as to not take up so much space here.
VB Code:
Set objWdApp = New Word.Application
Set objWdDoc = objWdApp.Documents.Open(FileName:="\\Taft\gis\test.doc")
Set objwdRange = objWdDoc.Content
With objwdRange.Find
.Replacement.ClearFormatting
.Text = "lotarea" 'this part works great.
.Replacement.Text = strlotarea
.Execute Replace:=wdReplaceAll
If Text1(6).Text = "R6" Then 'this part gives me nothing.
strlotarea = "6,000"
.Text = "lotarea"
.Replacement.Text = strlotarea
.Execute Replace:=wdReplaceAll
Re: Replacing text in Word Doc.
What you want to do? I don't see any errors on your code? give us a more details. Are you getting any errors. not working means, what?
Re: Replacing text in Word Doc.
What does Text1(6).text represent? Is it a text box, or is it referring to parts of the actual document text. If you're trying to get to a text box, then that isn't how Word references them when they're in a document.
Can I suggest recording a macro to learn what the syntax is for what you're trying to do, and then stripping out all the unnecessary bits?
zaza
Re: Replacing text in Word Doc.
Text1(6).Text is a text box on my from. After my other code executes a code will apperar in this text box. If "R6" is displayed in the text box I want the code I posted to execute. No errors, but nother appers on my word document. Where I have the word "lotarea" on the document will usually display a given number when the code is ran, but when Text1(6).Text displays "R6", it is left blank.
Thanks
Re: Replacing text in Word Doc.
Can anybody look at this again and give me an idea? I am still stuck.
Thanks.