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










-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.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

















  • 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.

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

















  • 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

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved