Add new worksheet using template

Feb 28, 2013 at 6:36 PM
Hi

I'd like to add a new worksheet to the existing active workbook based on a template (.xltx). I can add a new workbook with
Excel.Application.Workbooks.Open("path");
but this opens a new window. How can I load the template into the active book?

Thanks
Developer
Mar 1, 2013 at 4:50 PM
It seems to be no method for direct loading template into workbook. You can open template and then copy worksheet into your workbook.
Mar 1, 2013 at 6:36 PM
Excel.Application.Sheets.Add(Type:="TemplateWorkbookPath")
You can do it from your workbook variable that you are currently working in:
wkb.Application.Sheets.Add(Type:="TemplateWorkbookPath")
Mar 1, 2013 at 11:01 PM
Edited Mar 1, 2013 at 11:09 PM
Thanks Jon49 it works!
Mar 1, 2013 at 11:12 PM
I was just doing a reply, but you beat me to it! For anyone that looks at this in the future this is how it should be done in .NET:

That's how you would type it in VBA. Sorry, I should have put it in .NET for you.
Excel.Application.Sheets.Add(Type.Missing,Type.Missing, Type.Missing, "TemplateWorkbookPath")
I'm not sure what would be the equivalent of Type.Missing in C#, that is in VB.
Jan 16 at 5:47 PM
Edited Jan 16 at 5:48 PM
System.Reflection.Missing _missing = System.Reflection.Missing.Value;
String path = @"path of excel";
Excel.Application.Sheets.Add(_missing ,_missing , _missing , path );
``` Regards
Warren