My agent is creating an HTML output file, but the file has a .doc extension. Now I need to add headers and footers to it. The headers and footers are in an MS Word Template (.dot) file.
The error I get in the following code is “Automation object error”, which doesn’t mean squat (can I say that word?) to me.
Set officeApp = createObject(“Word.Application.9”)
officeApp.Options.ConfirmConversions = False
officeApp.Visible = True
Set officeDoc = officeApp.Documents.Add (filepath+""+tmplate$, False, 0, False)
Set para = officeDoc.Paragraphs(1)
Set rng = para.Range
rng.InsertFile filepath+""+docfn$
Call officeDoc.SaveAs (filepath+""+docfn$)
Call officeDoc.Close
Call officeApp.Quit
If I change the Add line to use no parameters (that is, no document template), then the code works (except that I don’t have the right headers and footers, which come from the template).
A cow-worker solved the problem for me. Apparently, if you Add a file using a template, you have to make it Active (if you don’t use a template, you don’t have to make it active). Here is the final code:
Set officeApp = createObject(“Word.Application.9”)