PDA

View Full Version : How do I Save to shared folder with original file name using macros?



klucas87
06-25-2012, 06:10 AM
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.

Tinbendr
06-25-2012, 01:56 PM
MSDN (http://msdn.microsoft.com/en-us/library/ff836084.aspx) specifically states that file will be overwritten.

You'll have to test it's existence before hand.

FileExists = (Dir(FileName) > "")'Returns True/False

Paul_Hossler
06-25-2012, 02:29 PM
Not sure what it is you're really looking to do

To save a doc opened from one folder back to your shared folder, I'd do something like this



Sub SaveIt()
ActiveDocument.SaveAs FileName:="O:\Team NF CV's\" & ActiveDocument.Name
End Sub


Paul