Additional to the VBA API described in the AO End User guide, Analysis for Office provides a tlb-file with enhanced COM functionalities. A type library (.tlb) is a binary file that stores information about a COM or DCOM object's properties and methods in a form that is accessible to other applications at runtime. Using a type library, an application can determine which interfaces an object supports, and invoke an object's interface methods. This document describes how to reference the tlb-file and how to access the functionalities. As an example this first part shows two simple functions you can use.
How to reference the API
You can reference the API by opening the “References” dialog in VBA. Select the file “BiApi.tlb” located in the installation folder of Analysis for Office.
After referencing this library the object browser (press F2) shows you the available classes.
General Coding
To access the functions you need the following general
coding:
Public mAO As Object Sub Init() On Error GoTo ErrorHandler Dim addIn As COMAddIn Dim automationObject As Object Set addIn = Application.COMAddIns("SBOP.AdvancedAnalysis.Addin.1") If addIn.Connect = False Then 'start AO if not started yet addIn.Connect = True End If Set automationObject = addIn.Object Set mAO = automationObject.GetApplication() Exit Sub ErrorHandler: MsgBox ("Problem occurred") End Sub Function AO() As IApplication If mAO Is Nothing Then Call Init End If Set AO = mAO End Function
Now you are able to call methods on the mAO object.
Samples
getConnections
This function returns all available connections for the
current workbook.
Sub ListOfConnections() Dim lEach As Variant Dim lList As Variant Dim aoCon As IConnection Dim lText As String Dim aoDoc As IDocument Set aoDoc = AO.GetActiveDocument() lList = aoDoc.GetConnections() For Each lEach In lList Set aoCon = lEach lText = lText + aoCon.SystemName + "; " + aoCon.SystemDescription + "; " + "connected: " + CStr(aoCon.IsConnected) + "; " + aoCon.RuntimeId + "; " + aoCon.BoeCuid + Chr(13) Next MsgBox (lText) End Sub
Logout
To disconnect your workbook you can call the logout function on the active document
Sub Logout() Set aoDoc = AO.GetActiveDocument() Call aoDoc.Logout End Sub
This is by the way to implement the already in idea place requested feature “Disconnect”
In the next part(s) I will describe in detail the other available functions.