Connection to SAP

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
Posts: 1
Joined: Mon Jul 22, 2019 2:10 pm

Connection to SAP

Post by Svyatoslav » Mon Jul 22, 2019 2:14 pm

Hello, it is possible to run vbs code for SAP inside macro scheduler?

my code

Code: Select all

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

Dim objExcel, objWorkbook, objSheet, i

Set objExcel = CreateObject("Excel.Application")

Set objWorkbook = objExcel.Workbooks.Open("C/temp/1.xlsx")

Set objSheet = objWorkbook.Sheets("List1")

For i = 2 to objSheet.UsedRange.Rows.Count

COL1 = Trim(CStr(objSheet.Cells(i, 1).Value)) 'Column1
COL2 = Trim(CStr(objSheet.Cells(i, 2).Value)) 'Column2
COL3 = Trim(CStr(objSheet.Cells(i, 3).Value)) 'Column3

session.findById("wnd[0]/tbar[0]/okcd").text = "VF03"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtVBRK-VBELN").text = COL1
session.findById("wnd[0]/usr/ctxtVBRK-VBELN").caretPosition = 10
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/titl/shellcont/shell").pressContextButton "%GOS_TOOLBOX"
session.findById("wnd[0]/titl/shellcont/shell").selectContextMenuItem "%GOS_VIEW_ATTA"

If InStr(session.findById("wnd[0]/sbar/pane[0]").Text, "The service <'Attachment list'> is not available") Then



session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").selectedRows = "0"
session.findById("wnd[1]/usr/cntlCONTAINER_0100/shellcont/shell").pressToolbarButton "%ATTA_EXPORT"
session.findById("wnd[2]/usr/ctxtDY_PATH").text = COL3
A = session.findById("wnd[2]/usr/ctxtDY_FILENAME").text
session.findById("wnd[2]/usr/ctxtDY_FILENAME").text = COL2 + A
session.findById("wnd[2]/usr/ctxtDY_PATH").caretPosition = 67

End If


msgbox "Process Complete"

User avatar
Marcus Tettmar
Site Admin
Posts: 7080
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK

Re: Connection to SAP

Post by Marcus Tettmar » Wed Jul 31, 2019 11:04 pm

If the code runs in a regular .vbs file outside of SAP then yes. But if the code accesses properties only exposed by the container - SAP - then probably not.
Marcus Tettmar |

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply