VBA Saving .xltm template as .xlsm

johnnyjoe1076

Board Regular
Joined
Jan 18, 2012
Messages
77
I have searched but I have not found a solution that has worked. I continually get a "runtime error '1004' method 'saveas' of object '_workbook' failed" in my .xltm file's code while it is attempting to save it as a .xlsm. I have tried different variations and methods but nothing seems to work. The following is the latest version of failure.

Code:
twb.SaveAs "H:\Continuous Improvement\Purchase Requisitions\Submitted Requisitions\" & prnum & ".xlsm", _
        FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False

prnum simply indicates the requisition number created for this file. I have verified that this aspect is working properly and not part of the problem. Any assistance would be greatly appreciated!
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
even same failure with the code as the following:

Code:
 Dim filename As String    filename = "H:\Continuous Improvement\Purchase Requisitions\Submitted Requisitions\" & prnum & ".xlsm"
    Application.DisplayAlerts = False
    'save file in folder
    Application.ScreenUpdating = True
    twb.SaveAs filename, FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
 
Upvote 0
Hi, try this :

twb.SaveAs "H:\Continuous Improvement\Purchase Requisitions\Submitted Requisitions" & prnum & ".xlsm", _
FileFormat:=52, CreateBackup:=False

or

twb.SaveAs "H:\Continuous Improvement\Purchase Requisitions\Submitted Requisitions" & prnum & ".xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled = 52, CreateBackup:=False
 
Upvote 0
Enter these lines to the beginning of your code


Dim twb As Workbook
Set twb = ActiveWorkbook

BTW , I assume you have write permissions to the directory on the H drive
 
Upvote 0
Enter these lines to the beginning of your code


Dim twb As Workbook
Set twb = ActiveWorkbook

BTW , I assume you have write permissions to the directory on the H drive

I do have the rights, and I have the coding, as you stated, already as part of it, except "Set twb = ThisWorkbook". I switched it to ActiveWorkbook just to see and still the same error.
 
Last edited:
Upvote 0
Seems to me like folder location is wrong....Please double check whether the folder location is correct

I test with c:\test\ and it's work good.
 
Upvote 0
Seems to me like folder location is wrong....Please double check whether the folder location is correct

I test with c:\test\ and it's work good.

I'm ahead of you, I tried that, I tried different folder locations, I tried recreating the folder, I tried different formats. I even tried changing the original file from an .xltm to .xlsm and still the same issue. I'm at a total loss. I have never had anything like this before with any save code.
 
Upvote 0
Here's a strange bit of additional information. Whenever the run-time error occurs, I click "debug" and then I continue the macro it works! But this only happens if I click debug and then continue. I even tried simply rigging the macro to rerun the code if failed and it doesn't work.
 
Upvote 0
Well I don't know exactly why, but I moved the "save code" to an earlier part in the code and it worked. Obviously there is issue somewhere else in my code hindering it. I'll have to trial and error it until I figure that aspect out.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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