cancel
Showing results for 
Search instead for 
Did you mean: 

How to integrate the fact that there is no data has not been selected in a VBA code?

0 Kudos

I'm making a vba code to import my data from SAP GUI I was wondering, how to do a loop that "clicks OK" when SAP tells us it "has not cut any data", this means that for this year for example no data has been entered in sap for a given transaction.

PublicSub RunGUIScript()

Dim W_Ret AsBoolean
 Sheets("Extraction").Select
Connect to SAP
 W_Ret = Attach_Session
 IfNot W_Ret ThenExitSubEndIfOnErrorGoTo myerr
 [script SAP]ExitSub

 myerr:
 MsgBox "Error occured while retrieving data", vbCritical + vbOKOnly
 EndSub

When there is this error message I want SAP to "click OK" and delete what is in its memory (I paste data from a "temp" sheet to my table)

I know that clicking on Ok is this command " session.findById("wnd[1]/tbar[0]/btn[0]").press"

Accepted Solutions (0)

Answers (1)

Answers (1)

daniel_mccollum
Active Contributor
0 Kudos
    If Not session.findById("wnd[1]/tbar[0]/btn[0]", False) Is Nothing Then
        session.findById("wnd[1]/tbar[0]/btn[0]").press
    End If

test for the condition, then press the button.

above is a crude test for existence, then press if exists.

The question isnt really clear from my perspective, but maybe this gets you 2 steps forwards.