I'm fairly new to VBA programming, but still managed to make a small code which exports an Excel sheet to a CSV file. This must be as user friendly as possible, so I came up with this:
Sub export_first()
Application.DisplayAlerts = False
Dim wb As Workbook, InitFileName As String, fileSaveName As String
InitFileName = ThisWorkbook.Path & "\Export nr1_" & Format(Date, "yyyymmdd")
Sheets("MySheetNameToExport").Copy
Set wb = ActiveWorkbook
fileSaveName = Application.GetSaveAsFilename(InitialFileName:=InitFileName, _
fileFilter:="Semicolon separated CSV (*.csv), *.csv")
With wb
If fileSaveName <> "False" Then
.SaveAs fileSaveName, FileFormat:=xlCSV, Local:=True
.Close
Else
.Close False
Exit Sub
End If
End With
End Sub
This works just fine. It is added to a button, and when the button is pressed, the codes does all the job. Now the thing is, my coworkers came up with an idea, that we should use columns that checks some values for the users (lets call them C, D) but when they export the worksheet, these columns must be ignored and not exported. What I tried to do is to extend the Sheets line like:
Sheets("MySheetNameToExport").Range("A:B, E:G").Copy
But when I add this modified line to my macro and run the code, Excel crashes and exports the very first sheet which is just some welcome text and is totally unnecessary.