silvin
06-28-2015, 03:15 AM
Hi everyone,
I am trying to set a macro which renames my file . I want my document name to contain the time and a variable (or more) from my document, such as author, subject, etc.
So the name of my file should be like this : yyyy_mm_dd_hh_mm_ss DOCVARIABLE "Subjecto" DOCVARIABLE "Author"
Untill now I have this code:
Sub SaveWithDate()
If ActiveDocument.Name = ActiveDocument.FullName Then
If Not Application.Dialogs(wdDialogFileSaveAs).Show Then Exit Sub
End If
CurrentFormat = ActiveDocument.SaveFormat
CurrentPathAndName = ActiveDocument.FullName
CurrentPath = Replace(ActiveDocument.FullName, ActiveDocument.Name, "")
NewNameSamePath = CurrentPath & Format(Now, "yyyy_mm_dd_hh_mm_ss") & ""
ActiveDocument.SaveAs FileName:=NewNameSamePath, FileFormat:=CurrentFormat
Kill CurrentPathAndName
End Sub
How can I insert the DOCVARIABLE in the file name?
Thank you all in advance for your help.
I am trying to set a macro which renames my file . I want my document name to contain the time and a variable (or more) from my document, such as author, subject, etc.
So the name of my file should be like this : yyyy_mm_dd_hh_mm_ss DOCVARIABLE "Subjecto" DOCVARIABLE "Author"
Untill now I have this code:
Sub SaveWithDate()
If ActiveDocument.Name = ActiveDocument.FullName Then
If Not Application.Dialogs(wdDialogFileSaveAs).Show Then Exit Sub
End If
CurrentFormat = ActiveDocument.SaveFormat
CurrentPathAndName = ActiveDocument.FullName
CurrentPath = Replace(ActiveDocument.FullName, ActiveDocument.Name, "")
NewNameSamePath = CurrentPath & Format(Now, "yyyy_mm_dd_hh_mm_ss") & ""
ActiveDocument.SaveAs FileName:=NewNameSamePath, FileFormat:=CurrentFormat
Kill CurrentPathAndName
End Sub
How can I insert the DOCVARIABLE in the file name?
Thank you all in advance for your help.