0

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

No data has been selected

this means that for this year for example no data has been entered in sap for a given transaction.

 Public Sub RunGUIScript()

 Dim W_Ret As Boolean
 Dim Société As String
 Sheets("Extraction").Select
 Société = Range("b9")
 ' Connect to SAP
 W_Ret = Attach_Session
 If Not W_Ret Then
 Exit Sub
 End If


 On Error GoTo myerr


 [script SAP]


 Exit Sub

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


 End Sub

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)

enter image description here

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
XDSSIOP
  • 91
  • 3
  • 11
  • 1
    Do you have to click OK with the mouse or pressing 'Enter' key is ok too? – Siyon DP Jun 17 '19 at 08:18
  • 2
    If Enter works, try `Application.SendKeys "{Enter}"` – Tim Stack Jun 17 '19 at 08:21
  • Yes, we can pressing "Enter" – XDSSIOP Jun 17 '19 at 08:22
  • @Tim Stack Thank you, it works, how do I delete the data in the memory? It still sticks to me the data from the transaction before – XDSSIOP Jun 17 '19 at 08:32
  • I wouldn't know, especially not without knowing how you copy said data – Tim Stack Jun 17 '19 at 08:35
  • According to this https://a4accounting.com.au/excel-vba-command-to-clear-the-clipboard/ you use `Application.CutCopyMode=False` – Nick.Mc Jun 17 '19 at 09:45
  • @Nick.McDermaid Okay, but I want to make a kind of loop, which says that when there is this message I don't want to copy it too. Because this message does not appear every month. – XDSSIOP Jun 17 '19 at 09:54
  • Why don't you clear the clipboard _before_ you call whatever you're calling. Then you don't have to check if you get the message - I'm guessing that in fact you are unable to check if the message appears – Nick.Mc Jun 17 '19 at 10:49
  • Good idea, but I don't know in advance if this message appears, it depends on the dates and transactions:( – XDSSIOP Jun 17 '19 at 12:09
  • `session.FindById("wnd[1]/tbar[0]/btn[0]").Press` should be simulating the button click of the popup. But you really need to work on asking questions with a [mcve]. The code you posted is irrelevant here, as you removed all of the parts pertaining to your problem. – Nacorid Jun 17 '19 at 13:45
  • @Nacorid Yes it's this command, actually I just want to make a loop thanks for your advice I'll check out the article – XDSSIOP Jun 17 '19 at 13:51

0 Answers0