How to Save as PDF automatically when doing the Mail Merge (VBA)2019 Community Moderator ElectionAuto 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
If I can solve Sudoku, can I solve the Travelling Salesman Problem (TSP)? If so, how?
What did “the good wine” (τὸν καλὸν οἶνον) mean in John 2:10?
Did Ender ever learn that he killed Stilson and/or Bonzo?
Relationship between sampajanna definitions in SN 47.2 and SN 47.35
Bacteria contamination inside a thermos bottle
Python if-else code style for reduced code for rounding floats
Adventure Game (text based) in C++
Most cost effective thermostat setting: consistent temperature vs. lowest temperature possible
Is it ever recommended to use mean/multiple imputation when using tree-based predictive models?
Fastest way to pop N items from a large dict
How can we have a quark condensate without a quark potential?
Is there a hypothetical scenario that would make Earth uninhabitable for humans, but not for (the majority of) other animals?
Why does overlay work only on the first tcolorbox?
Book: Young man exiled to a penal colony, helps to lead revolution
Brexit - No Deal Rejection
A diagram about partial derivatives of f(x,y)
Does multi-classing into Fighter give you heavy armor proficiency?
Instead of a Universal Basic Income program, why not implement a "Universal Basic Needs" program?
How are passwords stolen from companies if they only store hashes?
New passport but visa is in old (lost) passport
Why does a Star of David appear at a rally with Francisco Franco?
Why do newer 737s use two different styles of split winglets?
Have the tides ever turned twice on any open problem?
Is there a symmetric-key algorithm which we can use for creating a signature?
How to Save as PDF automatically when doing the Mail Merge (VBA)
2019 Community Moderator ElectionAuto 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.8k102437
15.8k102437
asked Mar 7 at 15:39
AyupovSukhrabAyupovSukhrab
914
914
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.
2017
2017
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