# Word macro to save .docm as pdf with specific filename of "surname"&"date"



## eyattwop (Nov 2, 2012)

Hi all,

This is my first venture into a forum so I will try to be detailed and concise! Here's the scenario:

Using Word 2007 I have a mail merged .docm file that includes two macros. The first is an AutoOpen macro that opens the "Find Entry" window, prompting the user to search for one recipient. The second macro sends the letter to the recipient via Outlook and prints the letter (to file the old fashioned way!). 

I need to then save the file as a pdf, with the filename of "[Surname] [First Name] [todays date].pdf", which I am currently doing manually. I've tried, without success, to get a macro to input the [Surname] and [First Name] merge fields into the filename in the Save As window. I've also tried bookmarking the fields to reference those in VBA, but I'm now out of my depth!


So there are two things I would love assistance with if possible:

Firstly, solving the auto-filenaming issue to recognise the current entry in the [Surname] and [First Name] merge fields.

Secondly, also having the date in the filename in YY-MM-DD format, to give "[Surname] [First Name] [todays date].pdf" (my letter uses 02 November 2012 format)</SPAN></SPAN>


I'd then like to add this to the end of my macro, which I will include below. Many thanks for taking the time to read this, and even more thanks if you can assist!!


Sub SendAndPrint()
'
' SendAndPrint Macro
' Sends MIT/EXT/ETC email to student email and prints
'
With ActiveDocument.MailMerge
.Destination = wdSendToEmail
.SuppressBlankLines = True
With .DataSource
.FirstRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
.LastRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
End With
.Execute Pause:=False
End With
With ActiveDocument.MailMerge
.Destination = wdSendToPrinter
.SuppressBlankLines = True
With .DataSource
.FirstRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
.LastRecord = ActiveDocument.MailMerge.DataSource.ActiveRecord
End With
.Execute Pause:=False
End With
End Sub


----------



## eyattwop (Nov 2, 2012)

Have just realised that posting a MS Word query to MrExcel may have been innapropriate given the name of the site! If so could someone please confirm and I will remove it.

many thanks

Eyattwop


----------



## Macropod (Nov 3, 2012)

Cross-posted at: Word macro to save .docm as pdf with specific filename of "surname"&"date" - Tech Support Forum
For cross-posting etiquette, please read: Excelguru Help Site - A message to forum cross posters 

FWIW, there is no objection to posting Word-related questions on this site. You'll find plenty in this very forum.


----------

