Why Doesn't this work

J

Jeff

I wrote this code in Excel VBA. I am attempting to do a merge with a
Word Document. I cannot get an "Test Text" to write in word


NameAndPath = "C:\Users\Admin\Desktop\test.doc"
Set wordapp = CreateObject("Word.Application")
wordapp.Documents.Open (fNameAndPath)
wordapp.Visible = True
TypeText Text:="Test Text"
 
A

Andy Pope

Hi,

You need to qualify which object has the TypeText method for you to use it.
So something more like this, also I assume the f before NameAndPath was a
typo.

'----------------------
NameAndPath = "C:\Users\Admin\Desktop\test.doc"
Set wordapp = CreateObject("Word.Application")
wordapp.Documents.Open (NameAndPath)
wordapp.Visible = True
wordapp.ActiveWindow.Selection.TypeText Text:="Test Text"
'----------------------

Cheers
Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top