I am using a VB macro to save my document with the filename I provide.
I want to use the current date and time in the file name. I use the following code:
Option Explicit
Private Sub CommandButton1_Click()
dtdate = Format(Now, "yyyy-mm-dd_hh_nn")
ActiveDocument.SaveAs filename:="C:\temp\" & dtdate & "Format." & "TEST3"
Unload SaveYourFile
ActiveDocument.Close
ActiveDocument.Close SaveChanges:=False 'The commond with will ensure that the SaveAs dialogue box will not open.
End Sub
Private Sub CommandButton2_Click()
Unload SaveYourFile
ActiveDocument.Close
ActiveDocument.Close SaveChanges:=False 'The commond with will ensure that the SaveAs dialogue box will not open.
End Sub
Private Sub TextBox1_Change()
End Sub
Private Sub TextBox1_Enter()
TextBox1.Text = "C:\temp\" & "Format." & "TEST3"
End Sub
Private Sub UserForm_Click()
End Sub
When I run the macro I get a compile error: Variable not defined. The syntax looks correct to me , there an obvious problem. Can anyone shed any light?
I want to use the current date and time in the file name. I use the following code:
Option Explicit
Private Sub CommandButton1_Click()
dtdate = Format(Now, "yyyy-mm-dd_hh_nn")
ActiveDocument.SaveAs filename:="C:\temp\" & dtdate & "Format." & "TEST3"
Unload SaveYourFile
ActiveDocument.Close
ActiveDocument.Close SaveChanges:=False 'The commond with will ensure that the SaveAs dialogue box will not open.
End Sub
Private Sub CommandButton2_Click()
Unload SaveYourFile
ActiveDocument.Close
ActiveDocument.Close SaveChanges:=False 'The commond with will ensure that the SaveAs dialogue box will not open.
End Sub
Private Sub TextBox1_Change()
End Sub
Private Sub TextBox1_Enter()
TextBox1.Text = "C:\temp\" & "Format." & "TEST3"
End Sub
Private Sub UserForm_Click()
End Sub
When I run the macro I get a compile error: Variable not defined. The syntax looks correct to me , there an obvious problem. Can anyone shed any light?