I'm hoping I am hoping some can help me
I am trying to use the below code to save files in Excel 2013 but I am getting the following error message:-
Method 'SaveAs' object'__Workbook' failed
Can anyone advise?
Sub SaveFile()
Dim Destwb As Workbook
Dim FolderName As String
Dim Sourcewb As Workbook
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Name As String
Set Sourcewb = ThisWorkbook
Set Destwb = ActiveWorkbook
Name = Cells(2, 2).Value
FolderName = Sourcewb.Path & "\Files_with_graphs"
FileExtStr = ".xls": FileFormatNum = 56
With Destwb
.SaveAs FolderName _
& "\" & Name & FileExtStr, FileFormat:=FileFormatNum
.Close False
End With
End Sub
You're using an invalid file format.
.xls is Excel 97-2003 format, for which you would want -4143
not 56
Seeing as you're working with the Excel object model you can just use the xlFileFormat
enumeration which is also better for compatibility:
FileFormatNum = xlFileFormat.xlWorkbookNormal
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.