MS Word Automation object error

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).

All help is greatly appreciated!

-Jeff

Subject: MS Word Automation object error

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”)

officeApp.Options.ConfirmConversions = False

Set officeDoc = officeApp.Documents.Add(filepath + "" + tmplate$, False, 0, False)

officeDoc.ActiveWindow.Activate ← the important line for using a template on the previous line

Call officeDoc.Paragraphs(1).Range.InsertFile (filepath+""+docfn$)

Call officeDoc.SaveAs (filepath+""+docfn$)

Call officeDoc.Close

Call officeApp.Quit

Subject: MS Word Automation object error

Hi Jeffrey…I Need your help… I’m trying to do exactly you did but without success.

I need create a HTML output file and then to add headers and footers… I’m New with LS… Please help me…

Sorry by my bad English.