How to Save as PDF automatically when doing the Mail Merge (VBA) The Next CEO of Stack OverflowAuto mail merge using Automator, Filemaker, Word and MailHow to split a mail merge and save files with a merge field as the namePublisher Mail Merge to PDF and Save as Merged FieldError Running VBS to Mail Merge with Task SchedulerMail merge to PDF rather than PrintSorting and filtering a Word Mail Merge with VBAVBA Mailmerge to pdf OutputSave PDF from SAPExcel Workbook to Create Word Document and Auto-Run Mail Merge from Excel WorkbookVBA Internet Explorer Automation - Select “Open” or “Save As” When Downloading a File
How did the Bene Gesserit know how to make a Kwisatz Haderach?
Return the Closest Prime Number
Which kind of appliances can one connect to electric sockets located in an airplane's toilet?
Multiple labels for a single equation
How did people program for Consoles with multiple CPUs?
Would a completely good Muggle be able to use a wand?
Written every which way
I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin
Inappropriate reference requests from Journal reviewers
"In the right combination" vs "with the right combination"?
What flight has the highest ratio of time difference to flight time?
Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?
What does convergence in distribution "in the Gromov–Hausdorff" sense mean?
Interfacing a button to MCU (and PC) with 50m long cable
Why don't programming languages automatically manage the synchronous/asynchronous problem?
Solidity! Invalid implicit conversion from string memory to bytes memory requested
MessageLevel in QGIS3
Why does standard notation not preserve intervals (visually)
Are there any limitations on attacking while grappling?
What is "(CFMCC)" on an ILS approach chart?
Several mode to write the symbol of a vector
Would a galaxy be visible from outside, but nearby?
Is it ever safe to open a suspicious html file (e.g. email attachment)?
Novel about a guy who is possessed by the divine essence and the world ends?
How to Save as PDF automatically when doing the Mail Merge (VBA)
The Next CEO of Stack OverflowAuto mail merge using Automator, Filemaker, Word and MailHow to split a mail merge and save files with a merge field as the namePublisher Mail Merge to PDF and Save as Merged FieldError Running VBS to Mail Merge with Task SchedulerMail merge to PDF rather than PrintSorting and filtering a Word Mail Merge with VBAVBA Mailmerge to pdf OutputSave PDF from SAPExcel Workbook to Create Word Document and Auto-Run Mail Merge from Excel WorkbookVBA Internet Explorer Automation - Select “Open” or “Save As” When Downloading a File
When I am trying to run the code below the following happens:
1) It opens a "Save PDF File As" Window
2) I have to manually type in the name
3) The code runs
I want to automate steps 1 and 2 so that the code runs without any manual inputs from me and saves it as whatever.pdf in whatever path.
I tried using ExportAsFixedFormat but the problem is that it is saving only the first page as pdf and the remaining 100+ records that are going through the mail merge are not being saved. On top of that, it still opens that Dialog Window from step 1.
ActiveDocument.ExportAsFixedFormat OutputFilename:=whatever.pdf, _
ExportFormat:=wdExportFormatPDF, etc.
The code:
Sub DoMailMerge()
Set myMerge = ActiveDocument.MailMerge
If myMerge.State = wdMainAndSourceAndHeader Or _
myMerge.State = wdMainAndDataSource Then
With myMerge.DataSource
.FirstRecord = 1
.LastRecord = 3
End With
End If
With myMerge
.Destination = wdSendToPrinter
.Execute
End With
End Sub
Any help on this would be greatly appreciated!
vba ms-word mailmerge
add a comment |
When I am trying to run the code below the following happens:
1) It opens a "Save PDF File As" Window
2) I have to manually type in the name
3) The code runs
I want to automate steps 1 and 2 so that the code runs without any manual inputs from me and saves it as whatever.pdf in whatever path.
I tried using ExportAsFixedFormat but the problem is that it is saving only the first page as pdf and the remaining 100+ records that are going through the mail merge are not being saved. On top of that, it still opens that Dialog Window from step 1.
ActiveDocument.ExportAsFixedFormat OutputFilename:=whatever.pdf, _
ExportFormat:=wdExportFormatPDF, etc.
The code:
Sub DoMailMerge()
Set myMerge = ActiveDocument.MailMerge
If myMerge.State = wdMainAndSourceAndHeader Or _
myMerge.State = wdMainAndDataSource Then
With myMerge.DataSource
.FirstRecord = 1
.LastRecord = 3
End With
End If
With myMerge
.Destination = wdSendToPrinter
.Execute
End With
End Sub
Any help on this would be greatly appreciated!
vba ms-word mailmerge
The code under "The code:" can't be the full code? It performs no save action - it only sends the merge result (three records) to the printer. You need to show the full code that's causing the behavior you describe, as a block. But FWIW you need to research saving a merge to separate documents - this is not something mail merge knows how to do. There are various approaches described in full detail that can be found on the Internet.
– Cindy Meister
Mar 7 at 21:40
This kind of thing has been addressed many times on many different web sites. See, for example, Send Mailmerge Output to Individual Files and Run a Mailmerge from Excel, Sending the Output to Individual Files in the Mailmerge Tips and Tricks threads at: msofficeforums.com/mail-merge/21803-mailmerge-tips-tricks.html and: windowssecrets.com/forums/showthread.php/…
– macropod
Mar 8 at 11:31
add a comment |
When I am trying to run the code below the following happens:
1) It opens a "Save PDF File As" Window
2) I have to manually type in the name
3) The code runs
I want to automate steps 1 and 2 so that the code runs without any manual inputs from me and saves it as whatever.pdf in whatever path.
I tried using ExportAsFixedFormat but the problem is that it is saving only the first page as pdf and the remaining 100+ records that are going through the mail merge are not being saved. On top of that, it still opens that Dialog Window from step 1.
ActiveDocument.ExportAsFixedFormat OutputFilename:=whatever.pdf, _
ExportFormat:=wdExportFormatPDF, etc.
The code:
Sub DoMailMerge()
Set myMerge = ActiveDocument.MailMerge
If myMerge.State = wdMainAndSourceAndHeader Or _
myMerge.State = wdMainAndDataSource Then
With myMerge.DataSource
.FirstRecord = 1
.LastRecord = 3
End With
End If
With myMerge
.Destination = wdSendToPrinter
.Execute
End With
End Sub
Any help on this would be greatly appreciated!
vba ms-word mailmerge
When I am trying to run the code below the following happens:
1) It opens a "Save PDF File As" Window
2) I have to manually type in the name
3) The code runs
I want to automate steps 1 and 2 so that the code runs without any manual inputs from me and saves it as whatever.pdf in whatever path.
I tried using ExportAsFixedFormat but the problem is that it is saving only the first page as pdf and the remaining 100+ records that are going through the mail merge are not being saved. On top of that, it still opens that Dialog Window from step 1.
ActiveDocument.ExportAsFixedFormat OutputFilename:=whatever.pdf, _
ExportFormat:=wdExportFormatPDF, etc.
The code:
Sub DoMailMerge()
Set myMerge = ActiveDocument.MailMerge
If myMerge.State = wdMainAndSourceAndHeader Or _
myMerge.State = wdMainAndDataSource Then
With myMerge.DataSource
.FirstRecord = 1
.LastRecord = 3
End With
End If
With myMerge
.Destination = wdSendToPrinter
.Execute
End With
End Sub
Any help on this would be greatly appreciated!
vba ms-word mailmerge
vba ms-word mailmerge
edited Mar 7 at 21:41
Cindy Meister
15.9k102437
15.9k102437
asked Mar 7 at 15:39
AyupovSukhrabAyupovSukhrab
1414
1414
The code under "The code:" can't be the full code? It performs no save action - it only sends the merge result (three records) to the printer. You need to show the full code that's causing the behavior you describe, as a block. But FWIW you need to research saving a merge to separate documents - this is not something mail merge knows how to do. There are various approaches described in full detail that can be found on the Internet.
– Cindy Meister
Mar 7 at 21:40
This kind of thing has been addressed many times on many different web sites. See, for example, Send Mailmerge Output to Individual Files and Run a Mailmerge from Excel, Sending the Output to Individual Files in the Mailmerge Tips and Tricks threads at: msofficeforums.com/mail-merge/21803-mailmerge-tips-tricks.html and: windowssecrets.com/forums/showthread.php/…
– macropod
Mar 8 at 11:31
add a comment |
The code under "The code:" can't be the full code? It performs no save action - it only sends the merge result (three records) to the printer. You need to show the full code that's causing the behavior you describe, as a block. But FWIW you need to research saving a merge to separate documents - this is not something mail merge knows how to do. There are various approaches described in full detail that can be found on the Internet.
– Cindy Meister
Mar 7 at 21:40
This kind of thing has been addressed many times on many different web sites. See, for example, Send Mailmerge Output to Individual Files and Run a Mailmerge from Excel, Sending the Output to Individual Files in the Mailmerge Tips and Tricks threads at: msofficeforums.com/mail-merge/21803-mailmerge-tips-tricks.html and: windowssecrets.com/forums/showthread.php/…
– macropod
Mar 8 at 11:31
The code under "The code:" can't be the full code? It performs no save action - it only sends the merge result (three records) to the printer. You need to show the full code that's causing the behavior you describe, as a block. But FWIW you need to research saving a merge to separate documents - this is not something mail merge knows how to do. There are various approaches described in full detail that can be found on the Internet.
– Cindy Meister
Mar 7 at 21:40
The code under "The code:" can't be the full code? It performs no save action - it only sends the merge result (three records) to the printer. You need to show the full code that's causing the behavior you describe, as a block. But FWIW you need to research saving a merge to separate documents - this is not something mail merge knows how to do. There are various approaches described in full detail that can be found on the Internet.
– Cindy Meister
Mar 7 at 21:40
This kind of thing has been addressed many times on many different web sites. See, for example, Send Mailmerge Output to Individual Files and Run a Mailmerge from Excel, Sending the Output to Individual Files in the Mailmerge Tips and Tricks threads at: msofficeforums.com/mail-merge/21803-mailmerge-tips-tricks.html and: windowssecrets.com/forums/showthread.php/…
– macropod
Mar 8 at 11:31
This kind of thing has been addressed many times on many different web sites. See, for example, Send Mailmerge Output to Individual Files and Run a Mailmerge from Excel, Sending the Output to Individual Files in the Mailmerge Tips and Tricks threads at: msofficeforums.com/mail-merge/21803-mailmerge-tips-tricks.html and: windowssecrets.com/forums/showthread.php/…
– macropod
Mar 8 at 11:31
add a comment |
1 Answer
1
active
oldest
votes
[Edit] Corrected object reference. Added SaveAs2
In the OP, an attempt is made to use a pseudo printer to save as a pdf. There are differences between the SaveAs pdf format and the variety of pdf pseudo printers. Is there a reason for printing to a PDF and saving that file, rather than doing a Save As and choosing the PDF format?
With myMerge
.Destination = wdSendToNewDocument
.Execute
End With
ActiveDocument.SaveAs2 "path & filename", wdFormatPDF
The following is sometimes needed to silence prompting with scripted saves. For the above tested method, there were no prompts, so it may not be needed.
Toggle off .DisplayAlerts
before SaveAs
Application.DisplayAlerts = wdAlertsNone
ActiveDocument.SaveAs2 "path & filename", wdFormatPDF
Application.DisplayAlerts = wdAlertsAll
Or
Dim tempDisplayAlerts As Long
tempDisplayAlerts = Application.DisplayAlerts
Application.DisplayAlerts = wdAlertsNone
ActiveDocument.SaveAs2 "path & filename", wdFormatPDF
Application.DisplayAlerts = tempDisplayAlerts
First of all, ActiveDocument.DisplayAlerts throws an error because I believe it is should be Application.DisplayAlerts and second of all, even if it worked it still does not resolve the issue of saving the merged file (with all the 100+ records) as pdf.
– AyupovSukhrab
Mar 7 at 17:09
Application.DisplayAlerts = False also kills any mailmerge from a document that is opened while that setting is active.
– macropod
Mar 8 at 11:34
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047602%2fhow-to-save-as-pdf-automatically-when-doing-the-mail-merge-vba%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
[Edit] Corrected object reference. Added SaveAs2
In the OP, an attempt is made to use a pseudo printer to save as a pdf. There are differences between the SaveAs pdf format and the variety of pdf pseudo printers. Is there a reason for printing to a PDF and saving that file, rather than doing a Save As and choosing the PDF format?
With myMerge
.Destination = wdSendToNewDocument
.Execute
End With
ActiveDocument.SaveAs2 "path & filename", wdFormatPDF
The following is sometimes needed to silence prompting with scripted saves. For the above tested method, there were no prompts, so it may not be needed.
Toggle off .DisplayAlerts
before SaveAs
Application.DisplayAlerts = wdAlertsNone
ActiveDocument.SaveAs2 "path & filename", wdFormatPDF
Application.DisplayAlerts = wdAlertsAll
Or
Dim tempDisplayAlerts As Long
tempDisplayAlerts = Application.DisplayAlerts
Application.DisplayAlerts = wdAlertsNone
ActiveDocument.SaveAs2 "path & filename", wdFormatPDF
Application.DisplayAlerts = tempDisplayAlerts
First of all, ActiveDocument.DisplayAlerts throws an error because I believe it is should be Application.DisplayAlerts and second of all, even if it worked it still does not resolve the issue of saving the merged file (with all the 100+ records) as pdf.
– AyupovSukhrab
Mar 7 at 17:09
Application.DisplayAlerts = False also kills any mailmerge from a document that is opened while that setting is active.
– macropod
Mar 8 at 11:34
add a comment |
[Edit] Corrected object reference. Added SaveAs2
In the OP, an attempt is made to use a pseudo printer to save as a pdf. There are differences between the SaveAs pdf format and the variety of pdf pseudo printers. Is there a reason for printing to a PDF and saving that file, rather than doing a Save As and choosing the PDF format?
With myMerge
.Destination = wdSendToNewDocument
.Execute
End With
ActiveDocument.SaveAs2 "path & filename", wdFormatPDF
The following is sometimes needed to silence prompting with scripted saves. For the above tested method, there were no prompts, so it may not be needed.
Toggle off .DisplayAlerts
before SaveAs
Application.DisplayAlerts = wdAlertsNone
ActiveDocument.SaveAs2 "path & filename", wdFormatPDF
Application.DisplayAlerts = wdAlertsAll
Or
Dim tempDisplayAlerts As Long
tempDisplayAlerts = Application.DisplayAlerts
Application.DisplayAlerts = wdAlertsNone
ActiveDocument.SaveAs2 "path & filename", wdFormatPDF
Application.DisplayAlerts = tempDisplayAlerts
First of all, ActiveDocument.DisplayAlerts throws an error because I believe it is should be Application.DisplayAlerts and second of all, even if it worked it still does not resolve the issue of saving the merged file (with all the 100+ records) as pdf.
– AyupovSukhrab
Mar 7 at 17:09
Application.DisplayAlerts = False also kills any mailmerge from a document that is opened while that setting is active.
– macropod
Mar 8 at 11:34
add a comment |
[Edit] Corrected object reference. Added SaveAs2
In the OP, an attempt is made to use a pseudo printer to save as a pdf. There are differences between the SaveAs pdf format and the variety of pdf pseudo printers. Is there a reason for printing to a PDF and saving that file, rather than doing a Save As and choosing the PDF format?
With myMerge
.Destination = wdSendToNewDocument
.Execute
End With
ActiveDocument.SaveAs2 "path & filename", wdFormatPDF
The following is sometimes needed to silence prompting with scripted saves. For the above tested method, there were no prompts, so it may not be needed.
Toggle off .DisplayAlerts
before SaveAs
Application.DisplayAlerts = wdAlertsNone
ActiveDocument.SaveAs2 "path & filename", wdFormatPDF
Application.DisplayAlerts = wdAlertsAll
Or
Dim tempDisplayAlerts As Long
tempDisplayAlerts = Application.DisplayAlerts
Application.DisplayAlerts = wdAlertsNone
ActiveDocument.SaveAs2 "path & filename", wdFormatPDF
Application.DisplayAlerts = tempDisplayAlerts
[Edit] Corrected object reference. Added SaveAs2
In the OP, an attempt is made to use a pseudo printer to save as a pdf. There are differences between the SaveAs pdf format and the variety of pdf pseudo printers. Is there a reason for printing to a PDF and saving that file, rather than doing a Save As and choosing the PDF format?
With myMerge
.Destination = wdSendToNewDocument
.Execute
End With
ActiveDocument.SaveAs2 "path & filename", wdFormatPDF
The following is sometimes needed to silence prompting with scripted saves. For the above tested method, there were no prompts, so it may not be needed.
Toggle off .DisplayAlerts
before SaveAs
Application.DisplayAlerts = wdAlertsNone
ActiveDocument.SaveAs2 "path & filename", wdFormatPDF
Application.DisplayAlerts = wdAlertsAll
Or
Dim tempDisplayAlerts As Long
tempDisplayAlerts = Application.DisplayAlerts
Application.DisplayAlerts = wdAlertsNone
ActiveDocument.SaveAs2 "path & filename", wdFormatPDF
Application.DisplayAlerts = tempDisplayAlerts
edited Mar 8 at 16:11
answered Mar 7 at 15:50
Ted D.Ted D.
2437
2437
First of all, ActiveDocument.DisplayAlerts throws an error because I believe it is should be Application.DisplayAlerts and second of all, even if it worked it still does not resolve the issue of saving the merged file (with all the 100+ records) as pdf.
– AyupovSukhrab
Mar 7 at 17:09
Application.DisplayAlerts = False also kills any mailmerge from a document that is opened while that setting is active.
– macropod
Mar 8 at 11:34
add a comment |
First of all, ActiveDocument.DisplayAlerts throws an error because I believe it is should be Application.DisplayAlerts and second of all, even if it worked it still does not resolve the issue of saving the merged file (with all the 100+ records) as pdf.
– AyupovSukhrab
Mar 7 at 17:09
Application.DisplayAlerts = False also kills any mailmerge from a document that is opened while that setting is active.
– macropod
Mar 8 at 11:34
First of all, ActiveDocument.DisplayAlerts throws an error because I believe it is should be Application.DisplayAlerts and second of all, even if it worked it still does not resolve the issue of saving the merged file (with all the 100+ records) as pdf.
– AyupovSukhrab
Mar 7 at 17:09
First of all, ActiveDocument.DisplayAlerts throws an error because I believe it is should be Application.DisplayAlerts and second of all, even if it worked it still does not resolve the issue of saving the merged file (with all the 100+ records) as pdf.
– AyupovSukhrab
Mar 7 at 17:09
Application.DisplayAlerts = False also kills any mailmerge from a document that is opened while that setting is active.
– macropod
Mar 8 at 11:34
Application.DisplayAlerts = False also kills any mailmerge from a document that is opened while that setting is active.
– macropod
Mar 8 at 11:34
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047602%2fhow-to-save-as-pdf-automatically-when-doing-the-mail-merge-vba%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The code under "The code:" can't be the full code? It performs no save action - it only sends the merge result (three records) to the printer. You need to show the full code that's causing the behavior you describe, as a block. But FWIW you need to research saving a merge to separate documents - this is not something mail merge knows how to do. There are various approaches described in full detail that can be found on the Internet.
– Cindy Meister
Mar 7 at 21:40
This kind of thing has been addressed many times on many different web sites. See, for example, Send Mailmerge Output to Individual Files and Run a Mailmerge from Excel, Sending the Output to Individual Files in the Mailmerge Tips and Tricks threads at: msofficeforums.com/mail-merge/21803-mailmerge-tips-tricks.html and: windowssecrets.com/forums/showthread.php/…
– macropod
Mar 8 at 11:31