ExcelApp nil

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

Only registered users are allowed to subscribe.
ExcelApp nil
ExcelApp nil 
Subscribe
Karim




Posts: 153
Joined: 2006-01-02
Hi,

I need to get filename when application started. this code works fine for Word, Powerpoint but not for Excel :( i have access violation because ExcelApp is nil ????



I use Office 2016 64bits and delphi 10.1 with last Add ins


procedure TAddInModule.adxCOMAddInModuleRibbonLoaded(Sender: TObject;
  const RibbonUI: IRibbonUI);
begin
  if (Self.HostType = ohaWord) then
  begin
     OriginFilename := WordApp.ActiveDocument.Name;
  end;

  if (Self.HostType = ohaExcel) then
  begin
       OriginFilename := ExcelApp.ActiveWorkbook.Name;
  end;

  if (Self.HostType = ohaPowerpoint) then
  begin
       OriginFilename := PowerpointApp.ActivePresentation.Name;
  end;
end;


Thanks
Posted 24 Aug, 2017 10:23:06 Top
Andrei Smolin


Add-in Express team


Posts: 14129
Joined: 2006-05-11
Hello Karim,

I've reproduced the issue and passed my sample project to our guys. Let's wait for their reaction.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Aug, 2017 04:09:48 Top
Andrei Smolin


Add-in Express team


Posts: 14129
Joined: 2006-05-11
Karim,

That property is initialized when an Application object is passed to the add-in through the OnConnect method of the IDTExtensibility2 COM interface. In your scenario, the Application object isn't initialized because the Office invokes the IRibbonExtensibility interface (and the OnRibbonLoaded event) before invoking the IDTExtensibility2.OnConnect() method. I suggest that you move this code to the OnAddinInitialize event of the add-in module.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Aug, 2017 05:32:33 Top
Karim




Posts: 153
Joined: 2006-01-02
Hi Andrei,

In the event OnAddinInitialize i have same error : access violation


Karim
Posted 25 Aug, 2017 07:00:14 Top
Andrei Smolin


Add-in Express team


Posts: 14129
Joined: 2006-05-11
Karim,

I suppose ExcelApp.ActiveWorkbook is nil.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Aug, 2017 08:36:29 Top
Karim




Posts: 153
Joined: 2006-01-02
Yes, ExcelApp.ActiveWorkbook is nil in realse mode but not in debug mode.
Posted 25 Aug, 2017 08:57:48 Top
Andrei Smolin


Add-in Express team


Posts: 14129
Joined: 2006-05-11
Karim,

This may relate to the way you start Excel.

Note that your add-in may be turned on via the COM Add-ins dialog. And, if there's no active workbook in this moment, you'll get the very same exception. That is, you must foresee that there's no active workbook in Excel.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 25 Aug, 2017 09:05:34 Top
Karim




Posts: 153
Joined: 2006-01-02
Andrei,

If it can help other person i use this control


if (Self.HostType = ohaExcel) then
  begin
    if (ExcelApp.Workbooks.Count >= 1) then
    begin
      OriginFilename := ExcelApp.ActiveWorkbook.Name;
    end;
  end;


Karim
Posted 28 Aug, 2017 14:22:50 Top
Andrei Smolin


Add-in Express team


Posts: 14129
Joined: 2006-05-11
Thank you, Karim!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 29 Aug, 2017 04:27:17 Top