Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Variable error

Status
Not open for further replies.

QueTech

MIS
Apr 13, 2003
79
US
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?
 


Hi,

You never stated the variable that the error was on, but I expect that its///
Code:
dtdate = Format(Now, "yyyy-mm-dd_hh_nn")
Did you intend that dtdate to be date or string?

You are assigning a STRING as the Format function is a string function.


Skip,
[sub]
[glasses] [red]Be Advised![/red] A chicken, who would drag a wagon across the road for 2 cents, is…
POULTRY in motion to PULLET for a PALTRY amount! [tongue][/sub]
 
I want the date to display in the filename in the follow format: "yyyy-mm-dd_hh_nn
 
Option Explicit
Private Sub CommandButton1_Click()
[!]Dim dtdate As String[/!]
dtdate = Format(Now, "yyyy-mm-dd_hh_nn")
...


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top