views:

27

answers:

1

Do Word documents have any scripting capabilities for presenting dynamic information? What I want to do is have the document dynamically pull in the contents of an HTML file and append it at the end of the document every time it is opened.

Anybody know if this is possible?

+2  A: 

Put the following in a code module. The AutoOpen routine is run each time the document is opened.

Public Sub AutoOpen()
    Dim currentDocument As Document
    Set currentDocument = ActiveDocument

    Dim sourceDocument As Document
    Set sourceDocument = Application.Documents.Open(FileName:="e:\mySourceName.docx")
    sourceDocument.Range.Copy
    sourceDocument.Close wdDoNotSaveChanges
    Set sourceDocument = Nothing

    Dim pasteRange As Range
    Set pasteRange = currentDocument.Range
    pasteRange.Collapse wdCollapseEnd

    pasteRange.Paste
End Sub
ForEachLoop