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
|
|
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.
|
|
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). |
|
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). |
|
Arie Bensimon
Posts: 20
Joined: 2007-06-05
|
Excel.Workbooks.add(Template as object)
how do I get the template obj? |
|
Sergey Grischenko
Add-in Express team
Posts: 7233
Joined: 2004-07-05
|
|
Arie Bensimon
Posts: 20
Joined: 2007-06-05
|
|