Hello! I'm new here, and this looks like the place I need to be! I see a lot of familiar friendly names from other forums. I hope someone can help me. I've got a good start on a template that creates letterhead for one of several office locations chosen on user form, and then performs a mail merge. I recorded macros to connect the data source and then perform the merge. They work. Next, I would like to show the newly merged document to the user. Currently, whatever document the user last had open remains the active document. I've searched and searched, but cannot find the answer. Can anybody help? I'm not a programmer; so please be gentle
Public Sub macConnectDataSource()
ActiveDocument.MailMerge.OpenDataSource Name:= _
"\\serverPATH\SampleData.csv" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="", SQLStatement:="", SQLStatement1 _
:="", SubType:=wdMergeSubTypeOther
ActiveDocument.SaveAs "c:\temp\TempMergeForm.docx"
End Sub
Public Sub macRunMerge()
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
'this closes the merge form, so user can see the merged document.
Documents("c:\temp\TempMergeForm.docx").Close SaveChanges:=wdDoNotSaveChanges
'The merged document gets the focus if user has no other documents open
'NOW: how to get focus on the merged form letters in event user
'has other documents open?
'ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges ! this closes the merged form
'ActiveDocument.SetFocus ! not supported
'Application.ScreenRefresh ! does nothing
'ActiveDocument.ActiveWindow.Activate ! causes document to detach
'ActiveDocument.Activate
'ArrangeWindows
'End Sub
'Public Sub ArrangeWindows()
'Documents(1).Close wdDoNotSaveChanges
'Documents(2).Activate
'Documents("Form Letters18").Activate
End Sub