I've mixed code and get good results considering that I wish to create csv file without header and for first 12 columns of file.
Also, I've found way to send message about successful creation. My main problem now, is the fact that I can't push code to ask me if file exists, and to create it just after confirmation.
The best solution will be if I may on easier way do next:
- create csv for range defined in code
- confirm if I wish to overwrite existing file
- open file in notepad
Below is code and obviously I need help
Private Sub CommandButton1_Click()
Dim fs As Object, a As Object, i As Integer, s As String, t As String, l As String, mn As String, PathCSV As String, NameCSV As String
PathCSV = "D:\BOM\"
NameCSV = "MMA - " & Format(Date, "mmmm yyyy") & ".csv"
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("D:\BOM\MMA - " & Format(Date, "mmmm yyyy") & ".csv", True)
For r = 5 To Range("A65536").End(xlUp).Row 'start in row 5 due row 1-4 is header
s = ""
c = 1
While c < 13
s = s & Cells(r, c) & ","
c = c + 1
Wend
a.writeline s 'write line
Next r
MsgBox "CSV file successfully save to " & PathCSV & NameCSV
End Sub