Reputation: 541
I have the below VBA which i have written and need a bit of help with the last bit
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
It essentially takes a highlighted column and produces a flat text file of the contents line by line.
The bit i need help with is the title of the output file. how can i add the date and time the macro was run to it? so that the output is testlist_date_time.lst
Upvotes: 0
Views: 4906
Reputation: 4363
Open "C:\Users\gaum\Desktop\Work\NCL\" & Format(Now(), "_yyyy-mm-dd_hh-mm") & ".lst" For Output As #1
...
Close #1
Upvotes: 3