Reputation: 131
The problem is that I am trying to save this spreadsheet (that I already have opened and saved as *.xlsx) as a *.csv file and I am having the error Runtime error 1004 Method 'SaveAs' of object '_Workbook' failed.
This is for Excel 2016.
Dim FilePath as string
FilePath = "U:\CAP Data - Every Month\ISEAdHoc\" & FileMonth & FileYear & "\"
Dim ISEAdHoc_FileName_CSV As String
ISEAdHoc_FileName_CSV = "ISEAdHoc_" & FileMonth & "CAP_" & Format(Now(), "YYYYMMDD") & "_" & Format(Now(), "HHMMSS")
Dim FileNameforCSVandPath As String
FileNameforCSVandPath = FilePath & ISEAdHoc_FileName_CSV & ".csv"
Sheets("ISEAdHoc").Activate
'ActiveWorkbook.SaveAs Filename:=FilePath & ISEAdHoc_FileName_CSV, FileFormat:=xlCSV, CreateBackup:=False, Local:=True
Workbooks(FileNameforCSVandPath).Close SaveChanges:=True
I expect to save the file as a *.csv. But for some reason I keep getting the error "Runtime error 1004 Method 'SaveAs' of object '_Workbook' failed." Please help!
Upvotes: 0
Views: 259
Reputation: 53
Your code seems to work fine as-is. Verify that your U:
drive mapped correctly.
I was able to copy your code and it worked on my side.
Upvotes: 1