Private Sub Command1_Click()
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:\" & Format(Date, "yyyy.mm.dd") & " " & Format(Time, "hh.mm.ss") & ".txt", True)
a.WriteLine ("This is a test.")
a.WriteLine ("这是一个测试用例。")
a.Close
Shell "notepad.exe " & "c:\" & Format(Date, "yyyy.mm.dd") & " " & Format(Time, "hh.mm.ss") & ".txt", vbNormalFocus
End Sub
先调用Time函数,得到当前时间。再用Str函数,把时间转成字符串,然后把这个字符串作为文件名就行了。
Visual Basic code
Conn.Execute "select 日期 as 日期, 时间 as 时间, 浓度 as 浓度 into [Excel 8.0;database=" & App.Path & "\Data" & Format$(Now, "yyyy-mm-dd HHNNSS") & ".xls].sheet1 from nongdubiao"
Dim 文件名 As String
文件名 = Format(Now, "YYYY-MM-DD_HHNNSS") & ".txt"
MsgBox 文件名