1

Deleting Orders on SAP is one of my Daily Tasks, I Have about 300 Orders to be Deleted everyday so each time i Go to the Transaction (VAO2) then Paste the order number from the excel then Choose options and Delete it, i wanted to script the whole process but each time to paste the new number i Copy from excel, so i created the below script but it goes with the same exact order "2268979048", I need to write the part of the code that let the script paste the number in the clipboard the time i run the Script (Note that i am not authorized to Use MASS deletion transaction)

If Not IsObject(application) Then
   Set SapGuiAuto  = GetObject("SAPGUI")
   Set application = SapGuiAuto.GetScriptingEngine

End If

If Not IsObject(connection) Then
   Set connection = application.Children(0)

End If

If Not IsObject(session) Then
   Set session    = connection.Children(0)

End If

If IsObject(WScript) Then
   WScript.ConnectObject session,     "on"
   WScript.ConnectObject application, "on"

End If

session.findById("wnd[0]").maximize

session.findById("wnd[0]/tbar[0]/okcd").text = "va02"

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[0]/usr/ctxtVBAK-VBELN").text = "2268979048"

session.findById("wnd[0]/usr/ctxtVBAK-VBELN").caretPosition = 10

session.findById("wnd[0]").sendVKey 0

session.findById("wnd[1]/tbar[0]/btn[0]").press
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Ahmed Fahmy
  • 11
  • 1
  • 2
  • Does your code, all the time, use the same parameters, except the order number? If yes, in which column of your Excel file, do the orders numbers exist? – FaneDuru Aug 15 '20 at 10:40
  • Hello! Still alive? I asked the above question in order to show you a way to iterate between the range cells, where the order numbers exist and replace "2268979048" with the cell value... – FaneDuru Aug 15 '20 at 12:31
  • Does this answer your question? [Get text from clipboard using GetText - avoid error on empty clipboard](https://stackoverflow.com/questions/9022245/get-text-from-clipboard-using-gettext-avoid-error-on-empty-clipboard) – Sandra Rossi Aug 16 '20 at 08:13

1 Answers1

1

Here's what may be helpful half-way lets say:

session.findById("wnd[0]/usr/ctxtVBAK-VBELN").text = InputBox("Pass in order to delete:", "Order deleting script")

This way you could provide each order at a time. But that does not solve your problem, I know. Your problem is more complex as you are trying to use a VBS. It's not easy to use a clipboard in vbs, but its possible.

If Not IsObject(application) Then
   Set SapGuiAuto  = GetObject("SAPGUI")
   Set application = SapGuiAuto.GetScriptingEngine
End If

If Not IsObject(connection) Then
   Set connection = application.Children(0)
End If

If Not IsObject(session) Then
   Set session    = connection.Children(0)
End If

If IsObject(WScript) Then
   WScript.ConnectObject session,     "on"
   WScript.ConnectObject application, "on"
End If

session.findById("wnd[0]").maximize

IterateThroughOrders()

Sub IterateThroughOrders()

    Dim userClippboard
    
    userClippboard = CreateObject("HtmlFile").ParentWindow.ClipboardData.GetData("text")
    
    For Each item In Split(userClippboard, Chr(13))
        If item <> "" Then
        
            'open new transaction no matter what
            session.findById("wnd[0]/tbar[0]/okcd").text = "/nVA02"
            
            session.findById("wnd[0]").sendVKey 0
            session.findById("wnd[0]/usr/ctxtVBAK-VBELN").text = item
            session.findById("wnd[0]/usr/ctxtVBAK-VBELN").caretPosition = 10
            session.findById("wnd[0]").sendVKey 0
            session.findById("wnd[1]/tbar[0]/btn[0]").press
            
            'the rest of the code goes here, supposedly there's more to that
            
        End If
    Next
    
End Sub

Explanation:

What happens here is that your clippboard is being loaded using a HtmlFile object, which is a way to get pass a wall that VBS have - it does not support clipboard handling easy way - but it works. Data copied from excel sheet from a column containing proper orders is being split by Chr(13) character, that is, is being splitted by breakline - new cell in this case. This split will make it possible to create a loop over every each value you just copied.