I have a template in word which receives input from the customer. My intention is that once they have finished editing it and have clicked on save, I create a new file name according to their input, and save it in a specific folder.
What I haven't managed to do is to find a trigger to activate the code after save is clicked.
Currently when I click save I get the box with the default file name (first line).
I'm attaching a screen shot of what I get at the moment (error and greyed out filename)
My code is
Private WithEvents App As Word.Application
Private WithEvents Doc As Word.Document
Private Sub Document_New()
' Set up application-level event handlers
Set App = Word.Application
End Sub
Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
End Sub
Private Sub App_DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean)
' use ThisDocument to save to same folder as template
strPath = ThisDocument.Path & ""
If Right(strPath, 1) <> "" Then
strPath = strPath & ""
End If
Doc.SaveAs2 FileName:="c:\test\newfilename.docx"
Doc.SelectContentControlsByTitle("DateTime")(1).Range.Text = Now()
Application.Quit SaveChanges:=wdSaveChanges
End Sub
[faulty image deleted by moderator]