vba save copy of workbook

Kaps_mr2

Well-known Member
Joined
Jul 5, 2008
Messages
1,589
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am trying to save a copy of the current workbook as a macro enabled workbook. However I get a wrong number of arguments or invalid property assignment on the line in Orange below. can anyone help pls ? thank you.

kind regards
Kaps

Rich (BB code):
Public Sub create_reporting_workbook()
Dim File_name As String
Dim d As Integer
Dim sheet_name As String
Dim new_file_name As String

new_file_name = reporting_month & " " & reporting_year & ".xlsm"


template_wb.SaveCopyAs new_file_name, FileFormat:=xlOpenXMLWorkbookMacroEnabled

   
    Set reporting_wb = ActiveWorkbook
   
    reporting_wb.Sheets(1).Name = "Summary"
 
Last edited by a moderator:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hello,

I am trying to save a copy of the current workbook as a macro enabled workbook. However I get a wrong number of arguments or invalid property assignment on the line in Orange below. can anyone help pls ? thank you.

kind regards
Kaps

Rich (BB code):
Public Sub create_reporting_workbook()
Dim File_name As String
Dim d As Integer
Dim sheet_name As String
Dim new_file_name As String

new_file_name = reporting_month & " " & reporting_year & ".xlsm"


template_wb.SaveCopyAs new_file_name, FileFormat:=xlOpenXMLWorkbookMacroEnabled

  
    Set reporting_wb = ActiveWorkbook
  
    reporting_wb.Sheets(1).Name = "Summary"
What value does new_file_name have?

Is template_wb a valid workbook object and is the workbook referred to loaded?
 
Upvote 0
A couple o things. You need to specify the whole path like...
Code:
"C:\Foldername\" & reporting_month & " " & reporting_year & ".xlsm"
with the path separator ("\") used betweeen drive, folder(s) and file name.
Also some characters can't be used in file names. I think a space maybe one of them. So you can use the following code to ensure that the file name is OK.
Code:
Public Function ValidFilePath(Arg As String) As String
Dim RegEx As Object
Set RegEx = CreateObject("VBScript.RegExp")
With RegEx
    .Pattern = "[\\/:\*\?""<>\|]"
    .Global = True
    ValidFilePath = .Replace(Arg, "_")
End With
Set RegEx = Nothing
End Function
To operate...
Code:
template_wb.SaveCopyAs ValidFilePath(new_file_name), FileFormat:=xlOpenXMLWorkbookMacroEnabled
HTH. Dave
 
Upvote 0
The SaveCopyAs method of the Workbook object contains only a single parameter, which specifies the filename. And the filename may or may not include the path. If it doesn't include the path, the workbook is saved in the current directory.

If your template workbook is already a macro-enabled workbook, you can simply do the following...

VBA Code:
template_wb.SaveCopyAs new_file_name

If your template workbook is not a macro-enabled workbook, try the following instead...

VBA Code:
    template_wb.Sheets.Copy
    
    With ActiveWorkbook
        .SaveAs Filename:=new_file_name, FileFormat:=xlOpenXMLWorkbookMacroEnabled
        .Close
    End With

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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