VBA从附着反射的多个打开实例中获取对象



我的公司最近从Attachmate EXTRA升级!附加反射。我们有许多宏运行在额外的屏幕抓取上。基本上,你会按下一个按钮来启动宏,它会要求你选择要在哪个额外的屏幕上运行它(我们总是为不同的系统打开3+(,然后宏只使用最近选择的(活动(会话。这是它的代码:

Private Function GetReflectionWindow(sessionName As String) As ExtraScreen
'Gets the most recent active reflection or extra window.
'Requires Reference: EXTRACOM
Dim sys As ExtraSystem: Set sys = CreateObject("EXTRA.System")
Dim sess As ExtraSession
'Set current sesion to most recently active session
If MsgBox("Click on the " & sessionName & " session and click 'OK' to continue.", vbOKCancel) = vbCancel Then End
Set sess = sys.ActiveSession
'Checks the session
If sess Is Nothing Then
MsgBox "Could not locate a Reflection or Extra session!", vbCritical
End
Else
Set GetReflectionWindow = sess.Screen
sess.Activate
End If
End Function

这不再适用于反射系统。相反,我在这里查看了这些文档。问题是,当使用CreateObject或GetObject时,它只查看第一个打开的实例,而不查看活动实例。

Sub GetNewReflectionWindow()
Dim App As Attachmate_Reflection_Objects_Framework.ApplicationObject
Dim screen As Attachmate_Reflection_Objects_Emulation_IbmHosts.IbmScreen
Dim Terminal As Attachmate_Reflection_Objects_Emulation_IbmHosts.IbmTerminal
Dim Frame As Attachmate_Reflection_Objects.Frame
Dim View As Attachmate_Reflection_Objects.View

Set App = GetObject(, "Attachmate_Reflection_Objects_Framework.ApplicationObject")
End Sub

我在文档或对象浏览器中看不到任何可以让我像Extra.System那样选择活动会话的内容。

我遇到了同样的问题,最终在所有地方的MicroFocus文档中找到了解决方案!访问VBA宏代码中所有打开的"反射工作区"对象

基本上,继续使用CreateObject来获得工作区,但在循环中进行,边走边重命名每个工作区:

Dim oSession As Object
'find all open sessions
Do
Set oSession = CreateObject("Reflection Workspace")
oActiveSession.AutomationServerName = "Unused"
Loop
'rename sessions back to original
Do
Set oActiveSession = CreateObject("Unused")
oActiveSession.AutomationServerName = "Reflection Workspace"
Loop

我将其放入自己的函数中,因为当您用完工作空间时,CreateObject会抛出一个错误。

最新更新