Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-08-2014, 02:52 PM
kp2009 kp2009 is offline How can I save a Word Document as a PDF file with a merged field filename? Windows 7 64bit How can I save a Word Document as a PDF file with a merged field filename? Office 2010 64bit
Novice
How can I save a Word Document as a PDF file with a merged field filename?
 
Join Date: Aug 2014
Posts: 2
kp2009 is on a distinguished road
Default How can I save a Word Document as a PDF file with a merged field filename?

Hi,



I have a document which I constantly change with the Mail Merge tool. I would like to create a macro that saves the document as a PDF file, but changes the filename to the merge field data in the document. How can I do this? I appreciate any help I could receive.

Thank you!
Reply With Quote
  #2  
Old 08-08-2014, 04:36 PM
macropod's Avatar
macropod macropod is offline How can I save a Word Document as a PDF file with a merged field filename? Windows 7 32bit How can I save a Word Document as a PDF file with a merged field filename? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,451
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

If you bookmark the field you want to use for the filename with the name 'Name', you could use a macro like the following. Simply preview the record to be output, then run the macro. The output file is saved to the same folder as the mailmerge main document.
Code:
Sub Demo()
Dim StrPath As String, StrName As String
With ActiveDocument
  StrPath = .Path & "\"
  StrName = .Bookmarks("Name").Range.Text  .SaveAs2 FileName:=StrPath & StrName & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False
End With
End Sub
Note: Given that previews don't reliably display the results in the way finishing the merge does when you're using much more than simple mergefields, this may not be a suitable solution. If not, a different approach will be required. Try it, though, and see if it produces the desired results.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]

Last edited by macropod; 08-08-2014 at 04:39 PM. Reason: Simplified macro
Reply With Quote
  #3  
Old 08-08-2014, 04:59 PM
kp2009 kp2009 is offline How can I save a Word Document as a PDF file with a merged field filename? Windows 7 64bit How can I save a Word Document as a PDF file with a merged field filename? Office 2010 64bit
Novice
How can I save a Word Document as a PDF file with a merged field filename?
 
Join Date: Aug 2014
Posts: 2
kp2009 is on a distinguished road
Default

It worked perfectly! Just one thing, is there any way I can also print the document automatically with the same macro?
Reply With Quote
  #4  
Old 08-08-2014, 05:06 PM
macropod's Avatar
macropod macropod is offline How can I save a Word Document as a PDF file with a merged field filename? Windows 7 32bit How can I save a Word Document as a PDF file with a merged field filename? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,451
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Simply insert:
.Printout
before:
End With
Note: this will print the document, not the PDF, but that shouldn't matter.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #5  
Old 08-19-2015, 06:19 AM
jbndylan jbndylan is offline How can I save a Word Document as a PDF file with a merged field filename? Windows 7 64bit How can I save a Word Document as a PDF file with a merged field filename? Office 2010 64bit
Novice
 
Join Date: Aug 2015
Location: Virginia, US
Posts: 1
jbndylan is on a distinguished road
Default

Hi, I get an "Compile error: Expected: end of statement" error on the save line.
dt = Format(CStr(Now), "mmddyyy")

ChangeFileOpenDirectory "\\vcuhshmo\groups\Claims Administration\CCU\PVOH\PVOH Mail Merge Letters\PVOH Mailers - Test\"

With ActiveDocument
' StrPath = .path & "\"
StrName = .Bookmarks("Name").Range.Text .SaveAs FileName:=StrName & ".docx"
End With
What have I missed?
Reply With Quote
  #6  
Old 08-27-2015, 11:45 PM
macropod's Avatar
macropod macropod is offline How can I save a Word Document as a PDF file with a merged field filename? Windows 7 64bit How can I save a Word Document as a PDF file with a merged field filename? Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,451
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

It looks like your code has merged two lines although that may be how you pasted it. Try
Code:
ChangeFileOpenDirectory "\\vcuhshmo\groups\Claims Administration\CCU\PVOH\PVOH Mail Merge Letters\PVOH Mailers - Test\"

With ActiveDocument
  StrName = .Bookmarks("Name").Range.Text
  .SaveAs FileName:=StrName & ".docx"
End With
Given your code has nothing to do with saving a document, you can't really expect anyone to advise on that...

Done properly, there is also no need for ChangeFileOpenDirectory!
Code:
Dim StrFldr as String
StrFldr = "\\vcuhshmo\groups\Claims Administration\CCU\PVOH\PVOH Mail Merge Letters\PVOH Mailers - Test\"

With ActiveDocument
  StrName = .Bookmarks("Name").Range.Text
  .SaveAs FileName:=StrFldr & StrName & ".docx"
End With
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
Reply

Tags
merge field, save-as, word 2010

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Save merged document as concatenated merge field values texas791 Word VBA 4 02-25-2014 07:35 PM
How can I save a Word Document as a PDF file with a merged field filename? Macro to create new word doc and save the file using String found in the document VBNation Word VBA 2 02-08-2013 07:14 AM
How can I save a Word Document as a PDF file with a merged field filename? Auto update Filename field Oliver Beirne Word VBA 4 10-19-2012 03:33 AM
How can I save a Word Document as a PDF file with a merged field filename? Save Filename using Document Text Knawl Word 11 10-10-2011 03:00 AM
Word: The document 'Filename' caused a serious error the last time ... martincruise Word 0 02-25-2010 01:47 AM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 04:02 AM.


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