Re: Word template automation
First, most things can be figured out of how to program by recording macros.
http://www.vbforums.com/showthread.php?t=402032
Next, you can open the documents using the template instead of having to copy/paste.
You may want to check out my Office FAQ for tips and code on automating Word from VB6.
Re: Word template automation
Thanks for the reply. But how can i open the documents with my customized header? There are about 400 word files with no header and footer yet. I want to put those header and footer on those 400 word docs. Is there any easier way to automate this?
Re: Word template automation
You can open each document one at a time and attach your template to it, saveas and close. Then repeat for the next document.
ActiveDocument.AttachedTemplate = "C:\MyTemplate.dot"
Re: Word template automation
wow great! let me try that. i got so many things to learn.
Re: Word template automation
Hey Rob, I tried but its not working.
Code:
oWord.Documents.Open "C:\Somefile.doc"
oWord.ActiveDocument.AttachedTemplate = "C:\Template.dot"
oWord.ActiveDocument.Save
oWord.ActiveDocument.Close
Is there something wrong with the code?
Re: Word template automation
depending on the content of your headers /footers, it might be easier to copy the document content into a new document based on the new template
you can use the code below in a loop through your documents
vb Code:
Dim olddoc As object, newdoc As object
Set olddoc = oword.Documents.Open("c:\somefile.doc")
Set newdoc = oword.Documents.Add("template.dot")
olddoc.Range.Copy
newdoc.Range.PasteSpecial
fname = olddoc.FullName
olddoc.Close False
newdoc.SaveAs fname ' overwrite old file
newdoc.Close
' loop to next file
Re: Word template automation
Works like a charm! Cheers mate!