You are viewing this site as a guest. You can still ask questions and help others! Join our Dev2Dev IT Community to receive your own blog, share your knowledge, and much more.

Macro to save to shared file with original document name?

1 reply [Last post]
Guest's picture
Guest

I have recorded a macro to save my files to a shared folder on my computer. Only issue being that when I use this on a new document it saves with the same file name and overwrites the document already saved. I want it to save the file with the original file name rather than the one used when recording the macro.

ChangeFileOpenDirectory "O:\Team NF CV's\"
ActiveDocument.SaveAs2 FileName:="O:\Team NF CV's\Jaumns.docx", FileFormat _
:=wdFormatXMLDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False, CompatibilityMode:=14
End Sub

It is the second line down where it uses the filename Jaumns.docx rather than the original unique file name.

Any help appreciated.

Lepa's picture
User offline. Last seen 22 weeks 5 days ago. Offline
Joined: 06/23/2008
Posts: 591
Re: Macro to save to shared file with original document name?

ActiveWorkbook.Name will give you the name of the workbook. So try the below

Change line FileName:="O:\Team NF CV's\Jaumns.docx" to FileName:="O:\Team NF CV's\" + ActiveWorkbook.Name

Give back to the community and help it grow!
* Help with unanswered forum questions and issues
* Register or login to share your knowledge at your own blog