PDA

View Full Version : [SOLVED] How to save as txt file name depend on current date and time



clif
10-03-2016, 06:02 PM
How to save as txt file name depend on current date and time



Sub txt()
Dim myFile As String, rng As Range, cellValue As Variant, i As Integer, j As Integer


myFile = "C:\Users\abc\log.txt"

Sheets("log").Select
Range("A1:M1").Select
Range(Selection, Selection.End(xlDown)).Select

Set rng = Selection
Open myFile For Output As #1
For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
cellValue = rng.Cells(i, j).Value

If j = rng.Columns.Count Then
Write #1, cellValue
Else
Write #1, cellValue,
End If
Next j
Next i
Close #1




End Sub

mana
10-04-2016, 04:11 AM
msgbox format(now(),"yyyymmdd_hhmmss")