- I have a spreadsheet that generates a word document, formats it, and then adds a bunch of text to the document, based on what was all selected and entered into the spreadsheet. All of this works great.
- What I am trying to do is somehow insert
VBAcode into the Word document at the time it was being generated within Excel.
Here is the specific code that I am trying to insert - ultimately this needs to go into Word VBA:
Private Sub Document_Close()
ActiveDocument.Saved = True
End Sub
I can’t seem to get Excel to insert this code into the Word document that is being generated. I know it is possible, but can’t figure it out. I tried several things and it accepts my code, but I have no idea where it is being inserted, because when I look for the inserted lines I can’t find them.
Here is the code that I am using to generate the Word document. Can someone please take a look and let me know how to insert the above code into this Document? Thanks for any help you can give.
Set wrdApp = CreateObject("Word.Application")
Set wrdDoc = wrdApp.Documents.Add
With wrdApp.Selection
‘A bunch of formatting code and text inputting is listed here for the word document.
End With
wrdApp.Visible = True
wrdApp.Activate
