View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
GB[_3_] GB[_3_] is offline
external usenet poster
 
Posts: 70
Default Controlling Word template from Excel


"Lee" wrote in message
...
I have an Excel add-in from which I can open a Word
template and insert info from the Excel workbook. I am
trying to insert AutoText that is saved in the template,
but I can't find the right syntax. This is what I have
written:

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
WordApp.Selection.Goto what:=wdGoToBookmark, Name:="PlaceMark"
WordApp.Selection.Insert("temp1").InsertAutoText

Whe=Selection.Range, RichText:=True
End With

What am I doing wrong?


I don't know, but I have two suggestions that may be helpful and one that is
probably wrong:

1. Your query is really to do with Word VBA code - why not try one of the
more relevant NGs? You will be more likely to get a helpful response.

2. We have an office app that does something similar. It actually runs a
mailmerge and then edits the resultant document within Word. We found the
best way was to set up a separate macro within word to do the editing. The
Excel code can trigger the word macro and then leave it to do its own work.
I seem to recall that it is far easier to debug the Word VBA code as a
separate macro within Word.

3. My Word Macro recorder recorded this, and you may like to use it in place
of the last line of your code:
NormalTemplate.AutoTextEntries("temp1").Insert Whe=Selection.Range

Incidentally, if you are using With WordApp ... End With, is it at all
helpful to start two of the lines WordApp.?

HTH a bit

Geoff