Creating a new Excel file based on a template in VBA

I am creating an application in Excel that will allow the user to select from a list of existing excel-based tools that have been created. They will select a specific tool and click the "Create New" button. After clicking this button, the user will be asked to specify the file. After entering the name, you need to create a new book and place it in this specific folder of the tool project. I am having trouble implementing this code. I was able to find examples of code that implements copying templates from an active workbook, but nothing to create something that is in another excel file entirely.

I believe that I need to make a copy of the book that the user must recreate, and then change the name and put the file in the right place.

I would post the code to show what I have done so far, but I really have not made progress.

Thanks,

+7
source share
2 answers

set wb = workbooks.add("x:\mytemplate.xls") allows you to create a NEW document and specify the file to use as the template.

+20
source

I used your code to read the file as a template, but then I can only read one file as a template, for example, I have the file name โ€œWeekly report 21โ€ as a template, where 21 is the week number, what if you want to read that the same pattern with a different week number as a suffix, without manually changing the number as a suffix?

Secondly, if this is not what we can do, how can I read the current active book as a template?

Dim strTemplate As String: strTemplate = "c: \ temp \ myfile.xlsm" Dim wb As Set Workbook Set wb = Workbooks.Add (strTemplate)

0
source

Source: https://habr.com/ru/post/1395076/


All Articles