Skip to Content
avatar image
Former Member

Hi! I have been trying to get this macro working in excel but i diont know why it does not work. Where should i input my login info?

do i need to input my login info, since I have auto log in? What changes do I need to do? What more info can I provide so that you can help me?

Sub SAPEXCEL()

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 = "KVBI"

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

session.findById("wnd[0]/usr/ctxtI_SALOR-LOW").text = "559737"

session.findById("wnd[0]/usr/ctxtR_BUDAT-LOW").setFocus

session.findById("wnd[0]/usr/ctxtR_BUDAT-LOW").caretPosition = 9

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

session.findById("wnd[1]/usr/cntlCONTAINER/shellcont/shell").focusDate = "20120101"

session.findById("wnd[1]/usr/cntlCONTAINER/shellcont/shell").firstVisibleDate = "20111226"

session.findById("wnd[1]/usr/cntlCONTAINER/shellcont/shell").selectionInterval = "20120101,20120101"

session.findById("wnd[0]/usr/ctxtP_DISVAR").setFocus

session.findById("wnd[0]/usr/ctxtP_DISVAR").caretPosition = 6

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

session.findById("wnd[1]/usr").verticalScrollbar.position = 22

session.findById("wnd[1]/usr").verticalScrollbar.position = 52

session.findById("wnd[1]/usr").verticalScrollbar.position = 97

session.findById("wnd[1]/usr").verticalScrollbar.position = 96

session.findById("wnd[1]/usr").verticalScrollbar.position = 95

session.findById("wnd[1]/usr").verticalScrollbar.position = 94

session.findById("wnd[1]/usr").verticalScrollbar.position = 93

session.findById("wnd[1]/usr").verticalScrollbar.position = 92

session.findById("wnd[1]/usr").verticalScrollbar.position = 91

session.findById("wnd[1]/usr").verticalScrollbar.position = 90

session.findById("wnd[1]/usr").verticalScrollbar.position = 89

session.findById("wnd[1]/usr/lbl[1,6]").setFocus

session.findById("wnd[1]/usr/lbl[1,6]").caretPosition = 4

session.findById("wnd[1]").sendVKey 2

session.findById("wnd[0]/tbar[1]/btn[8]").press

session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectedRows = "0"

session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").contextMenu

session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectContextMenuItem "&XXL"

session.findById("wnd[1]/usr/radRB_OTHERS").setFocus

session.findById("wnd[1]/usr/radRB_OTHERS").select

session.findById("wnd[1]/usr/radRB_1").setFocus

session.findById("wnd[1]/usr/radRB_1").select

session.findById("wnd[1]/tbar[0]/btn[0]").press

End Sub

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Apr 20, 2015 at 12:28 PM

    Hi,

    first of all,

    if you are Logged into SAP allready, you dont have to put your Logon Data anywhere ...

    Are you getting any Errormessages?

    If you're working in Excel you should correct the following lines:

    If Not IsObject(SapApplication) Then
       Set SapGuiAuto  = GetObject("SAPGUI")
       Set SapApplication = SapGuiAuto.GetScriptingEngine
    End If
    If Not IsObject(SAPconnection) Then
       Set SAPconnection = SAPapplication.Children(0)
    End If
    If Not IsObject(SAPsession) Then
       Set SAPsession    = SAPconnection.Children(0)
    End If
    

    Then it should work fine...

    greetings

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Shiv,

        I am fairly new to macro and scripting! Where can I check if "barberpole" running?

      In the Statusbar on the Right is an Arrow you can click- a Pane opens and you can see things like if youre Writing in "INS" or "OVR" and statusses about SAP-

      On the right outside is the "BarberPole" if this thing is disabled (not "scrolling") youre not Connected via Script

      Check ScriptMans reply pls

      You must!!! watch for correct Syntax

      Second thing about coding:
      You can spare much typing if you use a "shortcut" "With" and End With

      for Example:

      With SapSession
           .findbyid("wnd[0]").sendvkey(0)
      End With
      
      
      SAPScript.PNG (790 B)