I have an excel document that lists all of the documents in a given directory/folder. The file path is saved into column B. I have a macro that opens the document who's file path is in column B2.
I have a WORD document that copies the header and footer from a template document (open in the background)into a letter that is open (macro run from the letter which is the active document).
Both macros work independently - BUT when I run the macro from Excel and open the word document (a letter) the Word Macro will not run automatically - when I do run the word macro manually it then doesnt find the template file (still open in the background).
The EXCEL macro: Sub automateword() Dim strFolder As String
strFolder = Range("B2").Value
strDoc = Range("C2").Value
Set WordApp = CreateObject("word.Application")
WordApp.Documents.Open strFolder
WordApp.Visible = True
WordApp.Activate
DoCmd.RunMacro "Update"
Application.Run (Update)
WordApp.Documents.Save
'WordApp.Quit
End Sub
The WORD macro: Sub Update()
Application.Templates.LoadBuildingBlocks
Letter = ActiveDocument & " [Compatibility Mode]"
Template = "Rebranded.doc" & " [Compatibility Mode]"
'Activate Letter Template and copy header
Windows(Template).Activate
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.WholeStory
Selection.Copy
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
'Activate Letter to amend and Paste Header
Windows(Letter).Activate
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.WholeStory
Selection.Paste
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
'Activate Letter Template and copy footer
Windows(Template).Activate
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.WholeStory
Selection.Copy
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
'Active Letter to amend and Paste Footer
Windows(Letter).Activate
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.WholeStory
Selection.Paste
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
Any comments or help would be greatly appreciated - I have over 1000 documents that need amending.
Thanks
Bookmarks