I have a document that I use for work which is filled in every day with details of the shift to pass on to the shift coming on. These files are saved 01 01 2017 day 01 01 2017 Night 02 01 2017 day 02 01 2017 Night and so on, and filed for future reference so they are always saved with the date as the filename.
I also have two date fields in the file itself that I want to change with the filename but this is not as important so can be avoided if its not possible.
So what I am asking is! Is there a way to save the file multiple times with the dates changing in the text fields and the file name, is this possible.
Yes, you can do this with VBA. A skeleton macro is below. It saves the file in a directory "C:\foo" with the name in ISO-8601 format.
Sub Macro1()
Dim DateStr, FileStr As String
DateStr = Format$(Date, "yyyymmdd")
FileStr = DateStr & ".docx"
ActiveDocument.Save
ChangeFileOpenDirectory "C:\foo\"
ActiveDocument.SaveAs2 FileName:=FileStr, FileFormat:=wdFormatXMLDocument
End Sub
If (aiieeee!) you wanted to run this automatically to create a whole month's worth of files in one go, you'd wrap it in a loop, i.e.
For index As Integer = 1 To 30
; do stuff here
Next
The "30" could just as well be a variable, of course, calculated to be 28/29/30/31 according to the current month.