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

eyattwop

New Member
Joined
Oct 31, 2012
Messages
2
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
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
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
 
Upvote 0

Forum statistics

Threads
1,214,621
Messages
6,120,563
Members
448,972
Latest member
Shantanu2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top