附件反射的多个打开实例中的VBA GetObject?

时间:2019-11-15 17:52:47

标签: excel vba attachmate-extra

我的公司最近从Attachmate EXTRA升级了!进行Attachmate反射。我们有大量的宏在屏幕上运行。基本上,您将按下一个按钮来启动宏,它将要求您选择要在哪个屏幕上运行它(我们始终为不同的系统打开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

这不再适用于反射系统。相反,我查看了本文档here。问题在于,当您使用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这样选择活动会话。

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,终于在所有地方的MicroFocus文档中找到了解决方案! Accessing All Open "Reflection Workspace" Objects in VBA Macro Code

基本上,继续使用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会引发错误,因此我将其置于自己的函数中。