stockman256
New Member
- Joined
- Jul 25, 2010
- Messages
- 8
I have an excel spreadsheet with VBA code to generate a list and data for a word mailmerge. I've gotten the following code to work but I'd like to be able to use a variable to insert the filename instead of having to use a hyperlink and put the filename in the code. Is there a way to do that?
'Print Letters
Application.DisplayAlerts = False
Letter = Sheets("Control").Range("B17").Value
ActiveWorkbook.FollowHyperlink Address:="D:\OneDrive\My Docs\Letter 1.docx", NewWindow:=True
Dim DocName As String
DocName = ActiveDocument.Name
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
ActiveDocument.PrintOut Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentWithMarkup, Copies:=1, Pages:="", PageType:= _
wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
ActiveDocument.SaveAs2 Filename:=Letter
ActiveDocument.Close
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
'Print Letters
Application.DisplayAlerts = False
Letter = Sheets("Control").Range("B17").Value
ActiveWorkbook.FollowHyperlink Address:="D:\OneDrive\My Docs\Letter 1.docx", NewWindow:=True
Dim DocName As String
DocName = ActiveDocument.Name
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
ActiveDocument.PrintOut Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentWithMarkup, Copies:=1, Pages:="", PageType:= _
wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
ActiveDocument.SaveAs2 Filename:=Letter
ActiveDocument.Close
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges