MS Word Automation

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to export a large number of records one at a time into a word
template .dot file from access. The problem that I am having is that each
time a new document is created from the template I have to click on the
header of the Word application for the code in access to progress. The code
just seems to hand after the document is created. Aside from this
undesirable user intervention the sub-routine seems to work. How do I get
rid of the pause?

I used the following code:
Set objWord = CreateObject("Word.Application")
objWord.Documents.Add "The Path To The Template IS Here", _
NewTemplate:=False, DocumentType:=0)
ObjWord.Application.Visible =True
.....This is where we pause until I click on the Header of the Word App
objWord.Slection.MoveDown Unit:=wdLine, count:=12
The previous line skips past the protected(Form) sections of the document
Fonts are set and the fields are entered here.
objWord.Activedocument.SaveAs "File Path and name"
objWord.ActiveDocument.Close
objWord.Quit

Is there some way for me to give focus to Word from the code in Access
without manually clicking the Word header with each pass of the code?

Thanks,
Michael
 
Create a object variable for the document itself.
Then refer to the document variable instead of the application variable.
Also, you might want to use a With ... End With.

Regards,
Andreas
 
Back
Top