Loading new sheet from xltx template

Add-in Express™ Support Service
That's what is more important than anything else

Loading new sheet from xltx template
 
Arie Bensimon




Posts: 20
Joined: 2007-06-05
Basicaly I have a ribbon with a btnConnect.
When Clicked, the module makes the necessary connections and Updates several groups on the ribbon and a taskpane.

1)Now I would need load a new sheet from a template on connection.
2)I would need to know when that particular sheet is closing or to take the necessary steps to disconnect.
I tried to use the adxExcelEvents_WorkbookActivate and Marshal.GetActiveObject to get an instance of the workbook but GetActiveObject needs a ProgID that I don't have and I couldn't find an instance of the workbook in the sender of the WorkbookActivate ...

Would you put me on the right direction?
Thanks
Posted 17 Jun, 2007 08:11:21 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Arie.

You need to use the hostObj parameter to cast it to the Excel._Workbook interface. Could you please specify what exactly you want to load/unload ?
If you want to add new worksheets, you need to use the SheetActivate event instead of the WorkbookActivate one.




P.S. We always do our best to answer your forum requests as soon as
possible. However, we apply the rule "first in first out" with Premium
Support Service subscribers taking priority. Please understand it may take
us some time to do research on the issue. Please be assured we will let you
know as soon as the best possible solution is found.
Posted 18 Jun, 2007 17:12:14 Top
Arie Bensimon




Posts: 20
Joined: 2007-06-05
Hi Sergey, Its an Excel app.
To answer you question.
At first, The ribbon shows a connect button. When clicked, there's a Login form that verifies user creditials against an SQL server.
When login is sucessfull, some datasets are loaded and several groups on the riboon are made visible and bound to the data. A taskpane is also loaded with data reacting on selections made in ribbon combos. So that's the "loading".

at the end of the process. I need to load a new document from a template.
Right now what I do is:

Dim WithEvents wb As Excel.Workbook
Dim MyEventClass As ExcelWorksheetEventsClass1 = New ExcelWorksheetEventsClass1(Me)
Dim DistSheet As Excel.Worksheet
Private Sub OpenTemplate()
        File.Copy(Path.Combine(envSettings.InstallDir, "Distribution.xlsx"), Path.Combine(envSettings.InstallDir, "Distribution1.xlsx"), True)
        wb = ExcelApp.Workbooks.Open(Path.Combine(envSettings.InstallDir, "Distribution1.xlsx"))
        DistSheet = wb.Sheets("Sheet1")
        MyEventClass.ConnectTo(DistSheet, True)
End Sub

1) What I do is just copy an existing sheet. What I'd like is have excel create a new doc from a Template. How do I do that?

2) After connecting the event class to the sheet, I know when the sheet is ativated or desactivated. But I needed to know when that specific workbook closed. so I got it from wb.BeforeClose. The problem with adxExcelEvents_WorkbookBeforeClose is that all active workbook closing fires the event. So I got this set I think.

Just if you could help me with 1) or have other suggestions about 2).
Posted 19 Jun, 2007 02:31:15 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Arie.

1. You can use the Add method of the Excel.Workbooks interface.
2. You can add a custom property to the Excel workbook to identify specific workbooks (see the Excel._Workbook.CustomDocumentProperties property).
Posted 19 Jun, 2007 08:52:50 Top
Arie Bensimon




Posts: 20
Joined: 2007-06-05
Excel.Workbooks.add(Template as object)
how do I get the template obj?
Posted 19 Jun, 2007 09:53:33 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Posted 19 Jun, 2007 10:00:29 Top
Arie Bensimon




Posts: 20
Joined: 2007-06-05
Thanks!
Posted 20 Jun, 2007 03:06:02 Top