Load Template

G

Guest

1. Is it possible to load a Excel template in an existing workbook?
2. Also, is it possible to know from the workbook which template it has
loaded?

I used Application.WorkBooks.Add() but this opens a new workbook.
 
B

Bob Phillips

You can specify the template to open as an argument to Workbooks.Add

Workbooks.Add Template:="C:\Templates\myTemplate.xlt"

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
N

NickHK

You could try recording a macro of this action.
You would get something like:
Sheets.Add Type:="C:\Path to your templates\Template.xlt"

NickHK
 
G

Guest

Can you let me know the parameter to be passed in C#?
I am getting an exception. The API signature is

object Add(
[In, Optional] object Before,
[In, Optional] object After,
[In, Optional] object Count,
[In, Optional] object Type
);

I dont know what to pass in the fourth parameter. I passed the template
location but I am getting an exception 0x800A03EC.

I am making this api call
application.ActiveWorkbook.Worksheets.Add(Type.Missing,Type.Missing,Type.Missing,
@"c:\Documents and Settings\raverma\My Documents\Visual Studio
2005\Projects\ExcelWordAddins\Sample.xlt");
 
N

NickHK

You have to use the .Sheets collection not the .Worksheets collection.

Otherwise the Worksheets.Add method expects, for Type:
<From Help>
Type Optional Variant. Specifies the sheet type. Can be one of the
following XlSheetType constants: xlWorksheet, xlChart, xlExcel4MacroSheet,
or xlExcel4IntlMacroSheet. The default value is xlWorksheet.
</From Help>
Although the help is not clear on the above difference.

You could get your code working in Excel, with the help of the macro
recorder and Object Browser first, to use the correct syntax, methods etc,
then translate to C#.

NickHK

rahul said:
Can you let me know the parameter to be passed in C#?
I am getting an exception. The API signature is

object Add(
[In, Optional] object Before,
[In, Optional] object After,
[In, Optional] object Count,
[In, Optional] object Type
);

I dont know what to pass in the fourth parameter. I passed the template
location but I am getting an exception 0x800A03EC.

I am making this api call
application.ActiveWorkbook.Worksheets.Add(Type.Missing,Type.Missing,Type.Mis
sing,
@"c:\Documents and Settings\raverma\My Documents\Visual Studio
2005\Projects\ExcelWordAddins\Sample.xlt");
NickHK said:
You could try recording a macro of this action.
You would get something like:
Sheets.Add Type:="C:\Path to your templates\Template.xlt"

NickHK

it
has
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top