1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
'-Begin-----------------------------------------------------------------
'-Directives----------------------------------------------------------
Option Explicit
'-Sub SAPGUIScript----------------------------------------------------
Sub SAPGUIScript()
'-Variables-------------------------------------------------------
Dim SAPROTWr As ActiveXComponent
Dim Params(0) As Object
Dim ROTEntry As Dispatch
Dim App As Dispatch
Dim Version As String
Dim Con As Dispatch
Dim Ses As Dispatch
Dim oCtrl As Dispatch
Dim SesInf As Dispatch
Set SAPROTWr = New ActiveXComponent("SapROTWr.SapROTWrapper")
If SAPROTWr <> Nothing Then
Params(0) = "SAPGUI"
ROTEntry = Dispatch.call(SAPROTWr, "GetROTEntry", Params).toDispatch
If ROTEntry <> Nothing Then
App = Dispatch.get(ROTEntry, "GetScriptingEngine").toDispatch
If App <> Nothing Then
'-Shows SAP GUI Scripting version---------------------------
Version = Dispatch.get(App, "MajorVersion").toString & _
"." & Dispatch.get(App, "MinorVersion").toString
Debug.Print Version
'-Gets session 0 from connection 0--------------------------
Params(0) = 0
Con = Dispatch.call(App, "Children", Params).toDispatch
If Con <> Nothing Then
Ses = Dispatch.call(Con, "Children", Params).toDispatch
If Ses <> Nothing Then
'-Logs on the SAP system------------------------------
'-Sets the Client field-----------------------------
'-
'- Equivalent SAP GUI Scripting command:
'- session.findById("wnd[0]/usr/txtRSYST-MANDT").text = "001"
'-
'---------------------------------------------------
Params(0) = "wnd[0]/usr/txtRSYST-MANDT"
oCtrl = Dispatch.call(Ses, "findById", Params).toDispatch
Dispatch.put(oCtrl, "text", "001")
'-Sets the User field-------------------------------
'-
'- Equivalent SAP GUI Scripting command:
'- session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "BCUSER"
'-
'---------------------------------------------------
Params(0) = "wnd[0]/usr/txtRSYST-BNAME"
oCtrl = Dispatch.call(Ses, "findById", Params).toDispatch
Dispatch.put(oCtrl, "text", "BCUSER")
'-Sets the Password field---------------------------
'-
'- Equivalent SAP GUI Scripting command:
'- session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "minisap"
'-
'---------------------------------------------------
Params(0) = "wnd[0]/usr/pwdRSYST-BCODE"
oCtrl = Dispatch.call(Ses, "findById", Params).toDispatch
Dispatch.put(oCtrl, "text", "minisap")
'-Sets the Logon Language field---------------------
'-
'- Equivalent SAP GUI Scripting command:
'- session.findById("wnd[0]/usr/txtRSYST-LANGU").text = "EN"
'-
'---------------------------------------------------
Params(0) = "wnd[0]/usr/txtRSYST-LANGU"
oCtrl = Dispatch.call(Ses, "findById", Params).toDispatch
Dispatch.put(oCtrl, "text", "EN")
'-Sends a return to the SAP GUI---------------------
'-
'- Equivalent SAP GUI Scripting command:
'- session.findById("wnd[0]").sendVKey 0
'-
'---------------------------------------------------
Params(0) = "wnd[0]"
oCtrl = Dispatch.call(Ses, "findById", Params).toDispatch
Params(0) = 0
Dispatch.call(oCtrl, "sendVKey", Params)
'-Shows some information from SessionInfo object------
SesInf = Dispatch.get(Ses, "Info").toDispatch
If SesInf <> Nothing Then
Debug.Print Dispatch.get(SesInf, "SystemName")
Debug.Print Dispatch.get(SesInf, "SystemNumber").toString
Debug.Print Dispatch.get(SesInf, "Transaction")
Debug.Print Dispatch.get(SesInf, "User")
End If
End If
End If
App = Nothing
End If
ROTEntry = Nothing
End If
End If
Set SAPROTWr = Nothing
End Sub
'-Main-----------------------------------------------------------------
Public Sub Command1_Click()
SAPGUIScript
End Sub
'-End--------------------------------------------------------------------
|