top of page

SAP automation using VBA

Jul 23, 2024
1 min read

It took a really long time to get here.

Transaction VA05 could not be found, but it was in a category for Sales, and there is no Sales category in my PC environment.


Instead, I tried using transaction code CC05.


Normally you would make the standard definitions in SUB as shown below, and then write the scripts for the fields recorded using the previous method.


On Error GoTo Catch

Dim SapApp As Object

Dim SapConn As Object

Dim Session As Object

Dim SapGuiAuto As Object


Set SapGuiAuto = GetObject("SAPGUI")

Set SapApp = SapGuiAuto.GetScriptingEngine

Set SapConn = SapApp.Children(0)

Set Session = SapConn.Children(0)


Rem ------------------Start Connection------------------- -----------------------


Here is the process step.


Rem --------------------------------close connection----------------- -----------------------


Set Session = Nothing

SetSapConn = Nothing

Set SapApp = Nothing

Set SapGuiAuto = Nothing


Catch: 'Error trap for XXXX


End


However, for some reason it didn't work. When I looked at each line with the F8 key, I found that the number of Children (which would become Session) in the Connection was 0.


I didn't understand why the Session was 0 even though the SAPGUI was open and the Connection was established, so I decided it would be better to leave it all to Copilot. Result:

I'm a bit of a contrarian, so I started debugging from 4. There were no problems with the session.

However, when I restarted SAPGUI, for some reason a value was now entered into the session in the VBA local window.

Did I have to reboot it? It worked? I guess it doesn't work if the PC is old.


Operating state ↓




Comments


bottom of page