november 2015.

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")




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")


'Show Prompts

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

End If


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.

Read More 0 Comments

Analysis Office 2.1 Logoff via VBA

Since version 2.1 Analysis Office is now finally a VBA command to log out of the current system.


So far is nothing in the help file, but it is called in the SCN Forum under "Whats new in Analysis Office 2.1".


The command is:

Public Sub Logoff()

Call Application.Run("SAPLogoff",Parameter)

End Sub



  • True: With this value, the connection is restarted the system
  • False: With this value the connection will not restart the system


  • 0: faulty execution
  • 1: Successful execution
Read More 0 Comments