0

I have a python script that generates a .bas file which executes a process on SAP GUI. I pretend to run this script everyday to update the .bas file and run it.

I discarded the idea of using a driver (like selenium) to manipulate the SAP GUI directly, because the code is too long and I should refactor all the code.

A solution that I already tried was using the VBA Interpreter SmallBasic, but I got an error:

  • COMP-ERROR AT Main:10 *
    Description:
    (EXPR): SYNTAX ERROR (5)

The .bas file starts with:

Sub RPA_YVA05()
Application.DisplayAlerts = False
Dim SapGuiApp As Object
Dim oConnection As Object
Dim session As Object
Dim SAPCon As Object, SAPSesi As Object
Dim SAPGUIAuto As Object, SAPApp As Object

If SapGuiApp Is Nothing Then
    Set SapGuiApp = CreateObject("Sapgui.ScriptingCtrl.1")
End If
If oConnection Is Nothing Then
    Set oConnection = SapGuiApp.OpenConnection("xxxxxxxxxxxxxxxxxx", True)
End If
If SAPSesi Is Nothing Then
   Set SAPSesi = oConnection.Children(0)
End If
    
    'Application.DisplayAlerts = False

 With SAPSesi
        
    .findById("wnd[0]/usr/txtRSYST-MANDT").Text = "0000"
    .findById("wnd[0]/usr/txtRSYST-BNAME").Text = "xxxxxxx"

This generated script already works on Excel, but I want a way faster than opening an Excel file and loading the script manually everyday. Please help me

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Edumacsou
  • 15
  • 4
  • 1
    You can't use a vbscript file, or COM from Python ? – Tim Williams Apr 27 '21 at 19:23
  • There are lots of people in [SO](https://stackoverflow.com/questions/tagged/sap-gui+python) who use `win32com.client`. – Sandra Rossi Apr 28 '21 at 13:10
  • @TimWilliams, yesterday I tried to convert to .vbs and I made some changes, but I get compiling errors and I don't know how to Fix. I followed this [Convert bas to vbscript](https://stackoverflow.com/questions/13800794/excel-how-to-convert-bas-file-to-vbscript-exe-or-running-from-command-line) but didn't help. – Edumacsou Apr 28 '21 at 13:42
  • I would maybe create a new post around that - show your two scripts (bas/vbs) and describe the error(s) you're seeing. – Tim Williams Apr 28 '21 at 15:31

0 Answers0