VBA SaveAs Code failed

Tahas

Board Regular
Joined
Sep 10, 2008
Messages
152
Can somebody please help to identify what mistake am i committing? I'm using Excel 2010

Running macro gives me the message that...
Run time error 1004
Method 'SaveAs' of object' _workbook' failed

Here is how I set up the file format
If Val(Application.Version) < 12 Then
FileExtStr = ".xls": FileFormatNum = -4143
Else
FileExtStr = ".xlsm": FileFormatNum = 52
End If
Here is my code:
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Jeffrey Mahoney

Well-known Member
Joined
May 31, 2015
Messages
1,734
You need to create a variable to store the workbook you want to save.

Dim TWB as workbook

set WB = thisworkbook
With WB
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
end with

Without the With statement you could simply write it as
wb.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
 

Watch MrExcel Video

Forum statistics

Threads
1,100,140
Messages
5,472,751
Members
406,835
Latest member
steve43040

This Week's Hot Topics

Top