When creating new, empty workbooks, Excel names them "Workbook1", "Workbook2", "Workbook3" and so on. I want to create an empty, hidden workbook without consuming one of these default names. Let's say, the user already has "Workbook1" open, then my code creates a hidden workbook which will be named "Workbook2" by Excel. Now, if the user creates another new Workbook, Excel will call that one "Workbook3". I want it to be named "Workbook2". Of course, I could open an existing, empty workbook instead of creating one, but this makes it harder to deploy my addin.
1 Answers
2
votes
It's not possible to suppress or work around the automatic naming of new workbooks with the incremental counter. This counter works system-wide: it even kicks in when you start a new instance of the Excel application.
If you don't want to distribute an empty workbook with your project you could create one by leveraging the Open Office XML file format. Simplest would probably be to add the Open XML SDK to your project (free download, free license) and use that to create a new workbook on-the-fly. You can get the code for that by simply opening the basic workbook you want in the Open XMl SDK Productivity Tool. That generates the code required to create the Office Open XML file being opened. You should be able to pretty much copy/paste it...