SaveAs issue in VBA

Hi expert,

  I wrote the code to save as worksheet. but got error message is this.

"Run-Time error '1004', Method 'SaveAs' of object '-workbook' failed. i'm dummies in VBA, so I don't know how to fix it. 

Code:

Sub XLSXOutput()
    Dim wb As Workbook, InitFileName As String, fileSaveName As String
    InitFileName = "C:\Temp" & "\ - PECO_Output_ " & Format(Date, "mmddyyyy")
    Sheets("Sheet1").Range("A:K").Copy
    Set wb = ActiveWorkbook
    fileSaveName = Application.GetSaveAsFilename(InitialFileName:=InitFileName, filefilter:="Excel files , *.xlsx")
    With wb
        If fileSaveName <> "False" Then
            .SaveAs fileSaveName
            .Close
        Else
            .Close False
            Exit Sub
        End If
    End With

ThisWorkbook.Close savechanges:=False
End Sub
March 11th, 2015 6:01pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics