Analysis Office: Best Practice Connection

After the article "Connecting error in Analysis for Office via VBA" is often read, I would like to publish a few tips and tricks about working with Analysis Office.

 

The most important thing when you are working with VBA in Analysis Office, is the refresh of the DataSource(s). Otherwise nothing works. Once a connection to the Business Warehouse is established, each DataSource needs to be refreshed.

 

If you have only one DataSource, that is the source code:

 

Call Application.Run("SAPExecuteCommand", "Refresh", "DS_1")

 

If you have more than one DataSource, this is the source code:

 

Call Application.Run("SAPExecuteCommand", "Refresh")

 

So that you know if the refresh was successful, you should use the following source code:

 

Dim lResult As Long

lResult= Application.Run("SAPExecuteCommand", "Refresh")

 

or

 

Dim lResult As Long

lResult= Application.Run("SAPExecuteCommand", "Refresh", "DS_1"

 

Therefore you can check lResult to 1 or 0. If you refresh the DataSource(s) each time, a lot of time is wasted. To counteract this, there is the following source code:

Call Application.Run("SAPGetProperty", "IsDataSourceActive", "DS_1")

 

This command checks if the DataSource is already active. Here an example source code:

Sub AnalysisOfficeStart()

Dim lResult As Long

'Connection is running?

If Application.Run("SAPGetProperty", "IsConnected", "DS_1") Then

'Active DataSource?

If Not Application.Run("SAPGetProperty", "IsDataSourceActive", "DS_1") Then

'Refresh DataSource

lResult = Application.Run("SAPExecuteCommand", "Refresh", "DS_1")

Else

'Show Prompts

lResult = Application.Run("SAPExecuteCommand", "ShowPrompts", "DS_1")

End If

Else

lResult = Application.Run("SAPLogon", "DS_1", "Client", "User", "Password")

lResult = Application.Run("SAPExecuteCommand", "Refresh", "DS_1")

End If

End Sub

 

After this you can excute your own code.

Analysis Office - The Comprehensive Guide
Analysis Office - The Comprehensive Guide is a pdf book about SAP BusinessObjects Analysis Office. It is based on Analysis Office 2.3 and contains 227 Pages.
29,99 €
Analysis Office - The Comprehensive Guide 2nd edit
Analysis Office - The Comprehensive Guide is a pdf book about SAP BusinessObjects Analysis Office. It is based on Analysis Office 2.4 and contains 243 pages.
39,99 €

Write a comment

Comments: 0