(Solved) – Why won’t my macro that saves the excel sheet as a csv run?

(solved)-–-why-won’t-my-macro-that-saves-the-excel-sheet-as-a-csv-run?

I’m trying to save my file as a csv using a macro, so that I can later add a timer.

Here’s my code:

Sub Export_CSV()

    Dim MyPath As String
    Dim MyFileName As String
    Dim WB1 As Workbook, WB2 As Workbook

    Set WB1 = ActiveWorkbook

    MyFileName = "data_CSV_Export_"
    FullPath = WB1.Path & "" & MyFileName

    Application.DisplayAlerts = False

    If Not Right(MyFileName, 4) = ".csv" Then MyFileName = MyFileName & ".csv"
    With WB1
        .SaveAs FileName:=FullPath, FileFormat:=xlCSV, CreateBackup:=False
        .Close False
    End With
    Application.DisplayAlerts = True

End Sub

Error:

Method 'SaveAs' of object '_Workbook' failed

Does anyone know what’s wrong here?

Leave a Reply

Your email address will not be published. Required fields are marked *