Consulting

Results 1 to 2 of 2

Thread: How to save as txt file name depend on current date and time

  1. #1
    VBAX Contributor
    Joined
    Nov 2009
    Posts
    114
    Location

    How to save as txt file name depend on current date and time

    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

  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    msgbox format(now(),"yyyymmdd_hhmmss")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •