Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-25-2018, 02:26 PM
constructionjasont constructionjasont is offline Using Merge Data to Customize a File Name Windows 10 Using Merge Data to Customize a File Name Office 2016
Novice
Using Merge Data to Customize a File Name
 
Join Date: Jun 2017
Posts: 13
constructionjasont is on a distinguished road
Default Using Merge Data to Customize a File Name

I recorded a Word doc macro to update a Mail Merge based on an excel sheet array and then save as a PDF. It works almost exactly how I want, but I'm trying to customize the saved file's name. I know it's somewhere in the bold line below (with my attempt at it), can anyone tell me what I'm doing wrong?

ActiveDocument.ExportAsFixedFormat OutputFileName:= _
"C:\Users\j***\Desktop\" & Range("City") & ", " & Range("State") & " - GC Bid Instructions.pdf", _


ExportFormat:=wdExportFormatPDF, OpenAfterExport:=True, OptimizeFor:= _
wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
BitmapMissingFonts:=True, UseISO19005_1:=False
Reply With Quote
  #2  
Old 01-25-2018, 04:36 PM
macropod's Avatar
macropod macropod is offline Using Merge Data to Customize a File Name Windows 7 64bit Using Merge Data to Customize a File Name Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You can't just use Range("City") or Range("State") - you need to say where they come from; otherwise the code will assume they are Word ranges. Furthermore, unless each 'excel sheet array' spans only a single cell, neither Range("City") nor Range("State") would output anything.

To see how to get the relevant field values (and save the output), have a look at Send Mailmerge Output to Individual Files in the Mailmerge Tips and Tricks 'Sticky' thread at the top of the Mailmerge forum: https://www.msofficeforums.com/mail-...ps-tricks.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-31-2018, 02:55 PM
constructionjasont constructionjasont is offline Using Merge Data to Customize a File Name Windows 10 Using Merge Data to Customize a File Name Office 2016
Novice
Using Merge Data to Customize a File Name
 
Join Date: Jun 2017
Posts: 13
constructionjasont is on a distinguished road
Default

Thank you, that link solved it!

Would there be a reason then that it doesn't work running a macro in Excel? I have the excel vba as shown below, it will open the source document, but won't run the word macro. But if I run said macro directly through word it does fine. I tried finding a solution, but from what I can tell it should work?

Sub Create_Mailmerge_PDF()
Set appWd = CreateObject("Word.Application")
appWd.Visible = True
appWd.Documents.Open Filename:="C:\Users\j***\Source Doc.docx"
appWd.Run "Mailmerge_PDF"
End Sub
Reply With Quote
  #4  
Old 01-31-2018, 04:11 PM
macropod's Avatar
macropod macropod is offline Using Merge Data to Customize a File Name Windows 7 64bit Using Merge Data to Customize a File Name Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by constructionjasont View Post
TWould there be a reason then that it doesn't work running a macro in Excel? I have the excel vba as shown below, it will open the source document, but won't run the word macro. But if I run said macro directly through word it does fine. I tried finding a solution, but from what I can tell it should work?
For starters, if the Word document you're trying to open is a mailmerge main document, the whole process will stall as soon as the document opens, because Word will be waiting for you to respond to the SQL prompt that you get when opening such a document.

There are ways around that, but the coding becomes a whole lot more complex. See, for example: https://www.msofficeforums.com/mail-...html#post61768. Even that code doesn't generate the individual Word documents - you'd need to integrate the two approaches.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 02-01-2018, 07:34 AM
constructionjasont constructionjasont is offline Using Merge Data to Customize a File Name Windows 10 Using Merge Data to Customize a File Name Office 2016
Novice
Using Merge Data to Customize a File Name
 
Join Date: Jun 2017
Posts: 13
constructionjasont is on a distinguished road
Default

Thank you again very much!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Merge Data to Customize a File Name How do I customize OneNote's file system? gogreen OneNote 1 07-27-2016 09:38 AM
Using Merge Data to Customize a File Name Mail merge result in separate world files instead of one file containing all the data xdhbsh Mail Merge 3 12-24-2015 12:23 AM
Using Merge Data to Customize a File Name Mail Merge Drops Data File Office 2013 ottman88 Mail Merge 4 06-05-2015 03:16 AM
converting a word document to a data file for mail merge drsuis Mail Merge 4 02-21-2013 03:34 PM
Trying to merge label data from file ClayShannon Mail Merge 0 09-16-2009 10:08 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:08 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft