也许有人可以帮助我使用 VBA Excel 创建新的 SAP session
一些代码来理解问题
If Not IsObject(sap) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set sap = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = sap.Connections.Item(0)
End If
If Not IsObject(session) Then
Set session = Connection.Children(0)
End If
大多数情况下这一个工作正常。但有时这部分不起作用
Set session = Connection.Children(0)
例如当 SAP 超时发生时(空闲时间后自动注销)。 在那种情况下,我有
sap.Connections.Count
= 2
但是
Connection.Sessions.Count
= 0
看起来超时的连接仍然卡在 SAP 的某个地方。因此,当我尝试连接到第一个连接的第一个 session 时,出现错误,因为第一个连接中没有 session 。
我想要做的是创建新 session 。
我可以通过
Dim sapSession As SAPFEWSELib.GuiSession
Dim sapCon As SAPFEWSELib.GuiConnection
Set sapCon = sap.Connections.Item(0)
Set sapSession = Connection.sessions.Item(0)
sapsession.createsession
这个工作正常,但没有帮助,因为我仍然需要先设置 session
有没有办法在设置连接后创建 session ?
类似于 sapCon.createsession
有谁知道如何使用变量使用特定 session ?
Set sapSession = Connection.sessions.Item(0)
这工作正常,但当我尝试时
Dim SessionNumber as integer
....
SessionNumber = 0
Set sapSession = Connection.sessions.Item(SessionNumber)
它抛出一个错误“Bad index type for collection access”
最佳答案
Excel 要求 session 号为整数,因此可以使用 Cint() 的类型转换。奇怪的是,即使 SessionNumber 被定义为整数,也建议/要求这样做。
Dim SessionNumber
....
SessionNumber = 0
Set sapSession = Connection.sessions.Item(Cint(SessionNumber))
关于VBA SAP 创建 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44745416/