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










-1















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!










share|improve this question
























  • 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















-1















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!










share|improve this question
























  • 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













-1












-1








-1








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!










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












1 Answer
1






active

oldest

votes


















-2














[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





share|improve this answer

























  • 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










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
);



);













draft saved

draft discarded


















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









-2














[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





share|improve this answer

























  • 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















-2














[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





share|improve this answer

























  • 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













-2












-2








-2







[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





share|improve this answer















[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






share|improve this answer














share|improve this answer



share|improve this answer








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

















  • 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



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived