Automating AutoText retrieval

L

Lee

I have an Excel add-in that I use to open a Word template
and populate tables in the document with data from Excel.
I would like to insert AutoText saved in the template
before the tables are populated with data, but I cannot
figure out the correct syntax to automate this in Excel.
I tried posting this question on one of the Excel
newsgroups, but it was suggested I should try the Word NGs
instead.

Here is the code I am currently using:

Sub TextTest()
Dim WordApp As Word.Application
Set WordApp = CreateObject("word.application")
WordApp.Visible = True
With WordApp
Documents.Add Template:= _
"C:\Documents and Settings\all
users\Templates\rxtemptest.dot" _
, NewTemplate:=False, DocumentType:=0

.Selection.Goto what:=wdGoToBookmark,
Name:="PlaceMark"
.ActiveDocument.AttachedTemplate.AutoTextEntries
("Temp1").Insert Where:=Selection.Range, RichText:=True
End With
Set WordApp = Nothing

The code is breaking on the line that
begins .ActiveDocument, and it is giving me error code
450, Wrong number of arguments or invalid property
assigned. Can someone suggest the proper syntax?

Thanks, Lee
 
J

Jay Freedman

Hi, Lee,

Sometimes it's literally the smallest thing that gets you... in this case, a
dot. In the Where parameter of the Insert method, you need a dot before
Selection.Range so it will be recognized as WordApp.Selection.Range. (You're
also missing one before Documents in the Documents.Add statement. I'm not
sure how you got away with that.)
 
L

Lee

Thanks you! It's working perfectly now!
-----Original Message-----
Hi, Lee,

Sometimes it's literally the smallest thing that gets you... in this case, a
dot. In the Where parameter of the Insert method, you need a dot before
Selection.Range so it will be recognized as
WordApp.Selection.Range. (You're
 

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