G
Guus
Hello,
I frequently have to create Mail Merge results, so I want to create a macro
for this.
The macro has to do the following tasks:
1. Open my Main Document, with is always the same.
2. Connect the main document to a Data Source (because it changes all the
time,
I want to show a Dialog Box for selecting the Data Source.
3. Then I do the Merge to a New Blank Document
4. I want to save the merged document, here I want to show again a Dialog Box
5. At the end, I want to close the Main Document without saving.
The macro to be completed looks like this:
Dim Folder As String
Dim SourceFile As String
Dim fd As FileDialog
Folder = "D:\Feedback\"
'Standard directory
ChangeFileOpenDirectory Folder
'Open the existing template
Documents.Open Filename:="Primary_Document.doc", _
ConfirmConversions:=True, _
AddToRecentFiles:=False, Format:=wdOpenFormatAuto
'Show the Toolbar "Mail Merge"
CommandBars("Mail Merge").Visible = True
'Configure the Main Document
'1. TYPE
ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
'2. DATA SOURCE (MY PROBLEM IS "HOW TO SHOW A DIALOGBOX" !!!!!)
'3. Execute the merging
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
.DataSource.FirstRecord = wdDefaultFirstRecord
.DataSource.LastRecord = wdDefaultLastRecord
.Execute Pause:=False
End With
'4. Save the merged data
Dialogs(wdDialogFileSaveAs).Show
'5. Close the template
Windows("Primary_Document.doc").Activate
ActiveDocument.Close
Who can help me to complete the VBA code, specially for showing the Dialog
Box as mentioned in line "2." and "4."?
Thank you in advance,
Guus
I frequently have to create Mail Merge results, so I want to create a macro
for this.
The macro has to do the following tasks:
1. Open my Main Document, with is always the same.
2. Connect the main document to a Data Source (because it changes all the
time,
I want to show a Dialog Box for selecting the Data Source.
3. Then I do the Merge to a New Blank Document
4. I want to save the merged document, here I want to show again a Dialog Box
5. At the end, I want to close the Main Document without saving.
The macro to be completed looks like this:
Dim Folder As String
Dim SourceFile As String
Dim fd As FileDialog
Folder = "D:\Feedback\"
'Standard directory
ChangeFileOpenDirectory Folder
'Open the existing template
Documents.Open Filename:="Primary_Document.doc", _
ConfirmConversions:=True, _
AddToRecentFiles:=False, Format:=wdOpenFormatAuto
'Show the Toolbar "Mail Merge"
CommandBars("Mail Merge").Visible = True
'Configure the Main Document
'1. TYPE
ActiveDocument.MailMerge.MainDocumentType = wdFormLetters
'2. DATA SOURCE (MY PROBLEM IS "HOW TO SHOW A DIALOGBOX" !!!!!)
'3. Execute the merging
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
.DataSource.FirstRecord = wdDefaultFirstRecord
.DataSource.LastRecord = wdDefaultLastRecord
.Execute Pause:=False
End With
'4. Save the merged data
Dialogs(wdDialogFileSaveAs).Show
'5. Close the template
Windows("Primary_Document.doc").Activate
ActiveDocument.Close
Who can help me to complete the VBA code, specially for showing the Dialog
Box as mentioned in line "2." and "4."?
Thank you in advance,
Guus