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 for Office.
The most important thing when you are working with VBA in Analysis for 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:
1 |
Call Application.Run("SAPExecuteCommand", "Refresh", "DS_1") |
If you have more than one DataSource, this is the source code:
1 |
Call Application.Run("SAPExecuteCommand", "Refresh") |
So that you know if the refresh was successful, you should use the following source code:
1 2 |
Dim lResult As Long lResult= Application.Run("SAPExecuteCommand", "Refresh") |
or
1 2 |
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:
1 |
Call Application.Run("SAPGetProperty", "IsDataSourceActive", "DS_1") |
This command checks if the DataSource is already active. Here an example source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
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.
These posts might also be interesting:
author.
I am Tobias, I write this blog since 2014, you can find me on twitter and youtube. If you want you can leave me a paypal coffee donation. You can also contact me directly if you want.
Write a comment