Reputation: 11
I have been trying to do the following: In a template I have built in Excel 2016. When the template opens,the Workbook Open event is used to create a new workbook from this now open template and save it as a 'xlsm' file.I can't get the Workbooks.Add(template) to work. This is what I have attempted so far:
dim wb as workbook
set wb=workbooks.add(Me) 'Run-time error 1004' Application-defined or object defined error.
set wb = workbooks.add("x:\Users\name\Documents\name of template.xltm") Where name is user name and template is valid name copied from File Explorer. ' Run-time error 1004...
'Set wb = Workbooks.Add(Template:="C:\Users\Ed\Documents\Custom Office Templates\Itemized_Deduction.xltm") ' The exact path is shown in this attempt to show exactly what I was doing. I had to use a _ between the Itemized and Deduction- the compiler did not like it with just a space as it is shown in the folder. The error was the same.
It would sure help if MS would give complete examples of the samples so we,the users of their fine products, could get it the first time. I have been to this site, MS developer, Office Developer,and God knows where else and everything that was shown does not work.
Am I supposed to use a template of a workbook that is closed?
Can a XLTM template be used in this scenario?
Can someone show me how to use the .Add(template) please?
Upvotes: 1
Views: 6862
Reputation: 11
I had given it some thought after sleeping on it again and getting my head out of my *&^67! I was making it way to complicated. All I had to do was do a Save As on the template and the problem took care of itself. Thanks for the help and support Roy.
Upvotes: 0