Error "Method 'SaveAs' of object '_Workbook" failed

juanbolas

New Member
Joined
Dec 3, 2014
Messages
40
Office Version
  1. 365
Platform
  1. Windows
Hello,

I'm trying to generate a series of Excel (*.xlsx) files and am getting this error when trying to save the file.

I've taken out the non-offending code to make it simpler

Any help is appreciated.

VBA Code:
Sub PDP_RequestQuotes()

Dim CurRow As Integer

For Each cProveedor In ActiveWorkbook.Sheets("Unique").Range("ProveedoresUnique")
  
    Debug.Print cProveedor.Value
  
    Proveedor = ThisWorkbook.Sheets("Form_PDP").Range("E5").Value
    FilePath = "C:\Users\me\OneDrive\Escritorio\"
    FileName = Year(Date) & Right("00" & Len(Month(Date)), 2) & Right("00" & Len(Day(Date)), 2) & " - " & Proveedor & ".xlsx"
   
    ThisWorkbook.Sheets("Form_PDP").Copy
    ThisWorkbook.SaveAs FileName:=FilePath & FileName, FileFormat:=1
    ThisWorkbook.Close False

Next cProveedor

End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
I am not sure if this is exactly what is causing your issue, but it is generally a bad idea to choose variables names that are exactly the same as arguments in your code, i.e.
Rich (BB code):
    ThisWorkbook.SaveAs FileName:=FilePath & FileName, FileFormat:=1

And I do not see "1" as a valid option for the "FileFormat" argument.
Here is a list of the different FileFormat codes: XlFileFormat enumeration (Excel)

So see if this works better (untested):
VBA Code:
Sub PDP_RequestQuotes()

Dim CurRow As Integer
Dim Proveedor as String
Dim cProvedor as Range
Dim myFilePath as String
Dum myFileName as String

For Each cProveedor In ActiveWorkbook.Sheets("Unique").Range("ProveedoresUnique")
 
    Debug.Print cProveedor.Value
 
    Proveedor = ThisWorkbook.Sheets("Form_PDP").Range("E5").Value
    myFilePath = "C:\Users\me\OneDrive\Escritorio\"
    myFileName = Year(Date) & Right("00" & Len(Month(Date)), 2) & Right("00" & Len(Day(Date)), 2) & " - " & Proveedor & ".xlsx"
  
    ThisWorkbook.Sheets("Form_PDP").Copy
    ThisWorkbook.SaveAs FileName:=myFilePath & myFileName, FileFormat:=51
    ThisWorkbook.Close False

Next cProveedor

End Sub
 
Upvote 0
You are welcome.
So did that solve the issue?
 
Upvote 0

Forum statistics

Threads
1,223,952
Messages
6,175,595
Members
452,657
Latest member
giadungthienduyen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top