Workbooks CustomXMLParts

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

Workbooks CustomXMLParts
How to access CustomXMLParts 
Bob Devine


Guest


Hi

I'm using Excel 2013 and need access to the CustomXMLParts property of a workbook, and of course the Excel2000 TLB doesn't include in the workbook interface. What would be the best way to achieve this?

Thanks, Bob
Posted 16 Mar, 2020 20:14:02 Top
Andrei Smolin


Add-in Express team


Posts: 18823
Joined: 2006-05-11
Hello Bob,

You can import the type library of the Office version that provides that property' it is available on the Workbook declaration in Office 2007+. Have a look at https://www.add-in-express.com/forum/read.php?FID=1&TID=12731&MID=64876#message64876.

Alternatively, you can use late binding.


Andrei Smolin
Add-in Express Team Leader
Posted 17 Mar, 2020 01:04:41 Top
Bob Devine


Guest


Hi Andrei

I did actually try that (sorry should have mentioned) but get mismatches in the workbook type in the event handlers. I have a management class and pass the ExcelApplication and a TadxExcelAppEvents in via the constructor from the addin module. I then hook up all the event handlers in code.

I'd looked through the code to see what I could cast in the TadxExcelAppEvents to get around the workbook type mismatch.

Thanks, Bob
Posted 17 Mar, 2020 06:14:53 Top
Bob Devine


Guest


Just to elaborate - I have the Excel15 TLB in the uses section of my management class and do the ExcelApplication cast in the constructor after passing in the Excel2000 one from the addin module.

Cheers, Bob
Posted 17 Mar, 2020 06:49:53 Top
Andrei Smolin


Add-in Express team


Posts: 18823
Joined: 2006-05-11
Hello Bob,

You shouldn't mix the two object model versions: use namespace qualifier such as Excel2000.ExcelWorkbook and Excel15.ExcelWorkbook.


Andrei Smolin
Add-in Express Team Leader
Posted 17 Mar, 2020 07:06:28 Top
Bob Devine


Guest


Hi Andrei

Yes this is my problem - I need Excel15.ExcelWorkbook to get access to the CustomXMLParts but the event handlers in TadxExcelAppEvents require Excel2000.ExcelWorkbook. So in my constructor I have code such as:

FExcelEvents.OnWorkbookOpen := HandleWorkbookOpened;


Where FExcelEvents is the Excel2000-based TadxExcelAppEvents instance passed in from the addin module. Of course I get a type-mismatch here since my HandleWorkbookOpened handler uses Excel15.ExcelWorkbook.

Looking at the code in adxHostAppEvents.pas I could possibly modify it with an IFDEF to use Excel15_TLB but am not sure if this would have knock-on effects, or if there's a cleaner approach.

I only ever develop add-ins for Excel.

Thanks, Bob
Posted 17 Mar, 2020 07:28:14 Top
Andrei Smolin


Add-in Express team


Posts: 18823
Joined: 2006-05-11
Bob,

uses
  ...Excel_TLB, ...


procedure TAddInModule.adxRibbonTab1Controls0Controls0Click(Sender: TObject;
  const RibbonControl: IRibbonControl);
var book: Excel_TLB.ExcelWorkbook;
begin
  book := ExcelApp.ActiveWorkbook as Excel_TLB.ExcelWorkbook;
  ShowMessage(IntToStr(book.CustomXmlParts.Count));
end;


Is this what you need?


Andrei Smolin
Add-in Express Team Leader
Posted 17 Mar, 2020 08:24:30 Top
Bob Devine


Guest


Hi Andrei

Not exactly, but I think it's given me the clue :-) I think I just need to re-organise the code a bit, explicitly reference both type libraries and cast where required.

Thanks again for the great support.

Cheers, Bob
Posted 17 Mar, 2020 09:39:19 Top
Andrei Smolin


Add-in Express team


Posts: 18823
Joined: 2006-05-11
You are welcome, Bob!


Andrei Smolin
Add-in Express Team Leader
Posted 18 Mar, 2020 01:31:33 Top