0

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!

1
  • 1
    If I can suggest taking the approach laid out in this answer from today, I think you'll find your problem. Commented Jun 10, 2019 at 15:21

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Do not post questions as answers please.
@Damian eh, it's a legit reason for the code to be failing, and at 40 rep one cannot post comments - edited into a statement
@MathieuGuindon like it is now, yes. But he was asking to the OP. that wasn't an answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.