20Euclid17
New Member
- Joined
- Sep 5, 2017
- Messages
- 10
I currently have an excel sheet which serves as the input to a mail merge for a word doc. I want to write code so that at the push of a button, the excel sheet will save and the merged word document will open. However, for some reason when opening the merged doc like this disconnects the data source, so all my merge fields go blank and don't work. Note this doesn't occur when saving and closing the excel sheet, and then opening the word document manually. Here is my code so far (it's really simple):
Sub Button1_Click()
ActiveWorkbook.Save
Set wordapp = CreateObject("word.Application")
wordapp.Documents.Open "C:\Desktop\Template.doc"
wordapp.Visible = True
End Sub
I was hoping someone could explicitly tell me how to establish/re-establish the data connection from the word document to the access database I've linked the excel sheet to; either in VBA code for the word doc or in the code for the button I push in excel.
I've found half solutions and similar cases and have experimented, but have failed to make this work for my purposes. I'm not a programmer, I just want to add this time saving convenience to my auto-template generator. Any help is appreciated. Thanks
Sub Button1_Click()
ActiveWorkbook.Save
Set wordapp = CreateObject("word.Application")
wordapp.Documents.Open "C:\Desktop\Template.doc"
wordapp.Visible = True
End Sub
I was hoping someone could explicitly tell me how to establish/re-establish the data connection from the word document to the access database I've linked the excel sheet to; either in VBA code for the word doc or in the code for the button I push in excel.
I've found half solutions and similar cases and have experimented, but have failed to make this work for my purposes. I'm not a programmer, I just want to add this time saving convenience to my auto-template generator. Any help is appreciated. Thanks