Home » excel » excel – Macro to press a button in the Ribbon Menu

excel – Macro to press a button in the Ribbon Menu

Posted by: admin April 23, 2020 Leave a comment

Questions:

In a specific Excel sheet, I would like to have a macro to reach the “Analysis” button on Excel Ribbon and then to press a specific button “Alles aktualisieren”. You can see the screenshot for the clarification.

enter image description here

Analysis tab is an add-on of SAP-BI, so it is not an Standard Excel tab.

As one of the users suggested me, I recorded the macro, and I got the following Code, but when I run the macro, it is not working.

Sub Makro1()


Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Selection.UnMerge
Selection.UnMerge
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")
Application.Run Range("CallbackWorkbookSaved")

End Sub
How to&Answers:

Use the SAP API:

Public Sub SAP_Daten_aktualisieren()
Dim lResult As Variant

Application.StatusBar = Now & " Daten auf Afo-Blättern werden aktualisiert.."
DoEvents


lResult = Application.Run("SAPExecuteCommand", "Refresh", "All")
If lResult <> 1 Then
    Application.StatusBar = Now & " Problem beim Aktualisieren der SAP Daten "
    MsgBox "Fehler beim Aktualisieren der SAP Daten. SAPCode= " & lResult, vbCritical
Else
    Application.StatusBar = Now & " Fertig: SAP Daten wurden erfolgreich aktualisiert "
End If

End Sub

Answer:

Are you aware that macros can be recorded? I’d advise you to start recording a macro, press that button, stop the recording and see what your recorded macro looks like. Once you have this, if you stil have any questions, please edit your question, add the recorded code, we might have a further look at it.