0

First my test code

Sub mytest2()
If Not IsObject(MyApplication) Then
   Set SapGuiAuto = GetObject("SAPGUI")
   Set MyApplication = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
   Set Connection = MyApplication.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 MyApplication, "on"
End If


Dim MyTableStr As String
Dim MyTable As Variant

MyTableStr = "wnd[0]/usr/subSUB_ALL:SAPLCOIH:3001/ssubSUB_LEVEL:SAPLCOIH:1107/tabsTS_1100/tabpVGUE/ssubSUB_AUFTRAG:SAPLCOVG:3010/tblSAPLCOVGTCTRL_3010"
Set MyTable = session.findById(MyTableStr)
MyTable.VerticalScrollbar.Position = MyTable.VerticalScrollbar.Position + 1
Debug.Print MyTable.VerticalScrollbar.Position & " position"

This code will increase the table's vertical position and then fail on the debug.print line with error "Object doesn't support this action" Run-time error 445

If I add again the line

Set MyTable = session.findById(MyTableStr)

Between the .position line and the debug.print line, it works and the position gets printed.

Why does this happen ?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Shodan
  • 1,065
  • 2
  • 13
  • 35

1 Answers1

0

I found the answer in the SAP GUI scripting API pdf at http://www.synactive.com/download/sap%20gui%20scripting/sap%20gui%20scripting%20api.pdf

The important passage was in the description of the GuiButton control.

Function press

This emulates manually pressing a button. Pressing a button will always cause server communication to occur, rendering all references to elements below the window level invalid. The following code will therefore fail:

Set TextField = session.findById(".../txtF1") 
session.findById(".../btnPB5").press 
TextField.text = "Hello"

This is because when you execute commands, some will only affect the client state but other commands will cause communication with server and apparently when that happens, all previous object references are broken.

Changing the .VerticalScrollbar.Position of a GuiTableControl also causes communication with the server.

Shodan
  • 1,065
  • 2
  • 13
  • 35