Namespaces

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

Namespaces
MicroSoft and ADX (AddIn Express) Namespaces 
Michael Kaden


Guest


Dear Andrei,

following my Topic ?Â?Ð?ìCannot close Excel completely?Â?Ð?í, I would like to understand something more about Microsoft and ADX Namespaces in an ADX Excel AddIn project.

To make sure that I do not misunderstand the basics, first I would like to clarify some basics, as I understand them:

Namespaces refer to libraries containing Objects. They are DLL?Â?Ð?és and in the past, we called them Lib and we used the methods (procedures) of them in a project by, for example:

Private Declare Function GetCpuSpeed Lib "DLL2.dll" () As Integer

Today this is replaced by Namespaces which can consist of a Namespace Tree (Collections) and can contain Objects like

Microsoft.Office.InteropExcel.Workbook(Object)

The Objects then have Properties, Methods and Events. For the Microsoft Namespaces, I can find them documented well in the internet:


https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.tools.excel.workbook?view=vsto-2017

Or more general for the whole Excel Namespace:

https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.interop.excel.workbooks?view=excel-pia


Now I understand that the ADX AddIn has also some Namespaces with Objects, such as ExcelApp

AddinModule.CurrentInstance.ExcelApp.Workbooks

I cannot find the ExcelApp Object in the Object Browser.

On the Drop Down Menu in the code, I can see all Events (there are none for the ExcelApp object), Properties and Methods. But I must be aware that an ExcelApp Object exists.

So, the first question is, is there a way to get to get to know all the ADX Namespaces, like in the Microsoft websites mentioned above.

Then I learned, for example, using the Microsoft Object Excel.Application like in

Dim xlApp As New Microsoft.Office.Interop.Excel.Application

in an ADX Excel AddIn project can lead to problems as the behavior of more than one Excel process in the ADX AddIn is unpredictable. However, nothing prevents me using that object and finding out the problems later!

So it is recommended to use for example

Dim wb As Excel.Workbook = Nothing
Dim wbs As Excel.Workbooks = AddinModule.CurrentInstance.ExcelApp.Workbooks

Which, if I understand it correctly, will not create a new Excel process but will allow to open a new workbook in the running Excel Process with this

wb = wbs.Open(DataFile, 0, True)

Because of that, it is not possible to hide (run it in the background/invisible) only the newly created workbook?

But more to the point, how can I educate myself to understand what the differences are in using Namespaces (which ones = MS or ADX and how) in an ADX Excel AddIn in comparison to a Microsoft Visual Basic Project?

Sorry for having to ask these very basic questions, but I think we can save a lot of time if I get a better understanding of this system.

Thank you very much for your continuous good support and kind regards

Michael
Posted 24 Mar, 2021 17:24:01 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Hello Michael,

When talking about Office, you deal with so-called COM DLLs. In COM-enabled languages (such as VBA), Office namespaces are very simple: their names are "Excel", "Word", "VBIDE", etc. The Libs as you call them is a way to access non-COM DLLs. You use this way to access Windows API, for example.

In .NET, you use interops (in the Office case, you mostly deal with "primary interops") to access the internals of a COM DLL. A citation from the add-in Express manual:

An interop assembly for an object model is sort of a table mapping public members of Object model classes to addresses within the object model type library. The table provides the compiler with early binding info.


This is the root of the namespaces you talk about.

ExcelApp (or OutlookApp, WordApp, etc.) is a shortcut to the Excel.Application object that the host application provides your add-in with.

When a COM add-in loads, the host application provides it with a reference to the Application object of the host's object model; that is with an Excel.Application object in your case. Add-in Express stores that reference in the HostApplication property of the add-in module. When you create an add-in for Excel, Add-in Express creates a source-code property called ExcelApp; check the code of the add-in module of your add-in project. As you can see ExcelApp simply casts the HostApplication property to Excel._Application ("_Application" = "Application" minus events). This allows you to use the Excel.Application reference that the host provides, not to create other Excel.Application references. As you found, using other Excel.Application references may cause issues. For instance, in Outlook, using an Outlook.Application reference obtained using New Outlook.Application, CreateObject(), GetObject() and also the Application property that every object provide may cause security alerts; check https://www.add-in-express.com/outlook-security/index.php.


Andrei Smolin
Add-in Express Team Leader
Posted 25 Mar, 2021 03:06:59 Top