Save As Macro that changes the file name also

Joined
May 13, 2014
Messages
1
Reaction score
0
Hello,

I have a template letter document with a userform that insert text at the correct bookmarks.

I have recorded a macro that saves the file to a specific folder( easy enough) but I, if possible, I would like to include some code that changes the name of the file when I run the macro. For example, LastName,FirstName Contract

Someone has give me this but it doesn't seem to like the ME.

If should maybe point out that in the form I am using a txt called txtEmployeeName ( not sure if this is relevant)

Any input would be welcomed.

Thanks

Ross


Sub SaveAS()
'
' SaveAS Macro
'

Dim NewFileName As String
Dim NewFilePath As String


NewFilePath = "H:\HR\Reward & Shared Services\Shared Services Only\1 ~ Starters\3 ~ Contract Templates\DB Templates\"
NewFileName = Me.txtLastName & "," & Me.txtFirstName & ",Contract.docm"

'
ChangeFileOpenDirectory _
"H:\HR\Reward & Shared Services\Shared Services Only\1 ~ Starters\3 ~ Contract Templates\DB Templates\"
ActiveDocument.SaveAs2 FileName:= _
"H:\HR\Reward & Shared Services\Shared Services Only\1 ~ Starters\3 ~ Contract Templates\DB Templates\A-D contract v10-MACRO.docm" _
, FileFormat:=wdFormatXMLDocumentMacroEnabled, LockComments:=False, _
Password:="", AddToRecentFiles:=True, WritePassword:="", _
ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False, CompatibilityMode:=14
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top