VBA将日期和时间放在输出文本文件中

时间:2013-07-09 14:49:59

标签: vba

我有以下的VBA,我已经写过并需要最后一点的帮助

Sub testlist()
Open "C:\Users\gaum\Desktop\Work\NCL\testlist.lst" For Output As #1
For NR = 1 To Selection.Rows.Count
For NC = 1 To Selection.Columns.Count
ExpData = Selection.Cells(NR, NC).Value
If IsNumeric(ExpData) Then ExpData = Val(ExpData)
If IsEmpty(Selection.Cells(NR, NC)) Then ExpData = ""
If NC <> NumCols Then
If Not ExpData = "FilePath" Then Print #1, ExpData
End If
Next NC
Next NR
Close #1
End Sub

它基本上采用突出显示的列,并逐行生成内容的平面文本文件。

我需要帮助的是输出文件的标题。如何添加宏运行的日期和时间?所以输出是testlist_date_time.lst

1 个答案:

答案 0 :(得分:3)

Open "C:\Users\gaum\Desktop\Work\NCL\" & Format(Now(), "_yyyy-mm-dd_hh-mm") & ".lst" For Output As #1
    ...
Close #1