Moving from Extra! to Reflection Desktop, and missing the "Sessions" collection object?

If you have done much scripting with Extra! you probably know that the Extra! automation interface provides a "Sessions" collection object that gives you a way to access all Extra! session objects currently opened. It's a pretty handy thing for various situations, but there is no direct equivalent collection object available in the Reflection Desktop interface. Fortunately, there is still a way to achieve the same goal in Reflection Desktop VBA.

The functions "GetAllFrames" and "GetAllViews" in this VBA code will return all Reflection "Frame" objects, or all Reflection "View" objects running in any instance of the Reflection Workspace currently open. Once you have the "Frame" for a Reflection Workspace window, you can get all "View" objects running in it. Each Terminal session runs inside a View, and is accessed using the View's "control" property.

Copy the following to a module in the Reflection Visual Basic Editor, open a few sessions in multiple Reflection Workspace windows, and try out the test below!

Code:
Option Explicit

'Returns a Collection object that contains all open Reflection Frame objects
Function GetAllFrames() As Collection
   Dim Frames As New Collection
   Dim rApp As Attachmate_Reflection_Objects_Framework.ApplicationObject

   On Error Resume Next
   
   'By default, all Reflection Application objects will have the
   '"AutomationServerName" of "Reflection Workspace".
   'So, this method of discovering all currently-running Application
   'objects works as long as you have not used another program
   'that changes the default value on these to something else.
   Do
      Set rApp = GetObject("Reflection Workspace")
      If Err = 0 Then
         Frames.Add rApp.GetObject("Frame")
         rApp.AutomationServerName = "Reflection Workspace - already counted"
      Else
         Err.Clear
         Exit Do
      End If
   Loop
    
   'Reset back to the original AutomationServerName...
   Do
      Set rApp = GetObject("Reflection Workspace - already counted")
      If Err <> 0 Then
         Err.Clear
         Exit Do
      End If
      rApp.AutomationServerName = "Reflection Workspace"
   Loop
    
   Set GetAllFrames = Frames
End Function

'Returns a Collection object that contains all open Views
'in all Reflection Frame objects.
Function GetAllViews() As Collection
   Dim Frames As Collection
   Dim Views As New Collection
   Dim i As Long
   Dim f As Frame

   Set Frames = GetAllFrames()
   
   For Each f In Frames
        If f.ViewCount <> 0 Then
            For i = 1 To f.ViewCount
                Views.Add f.View(i)
            Next
        End If
   Next

   Set GetAllViews = Views
End Function



'Test...print all view titles to the intermediate window.
Sub ReportAllViewTitles()
   Dim Views As Collection
   Dim v As View
   
   Set Views = GetAllViews()
   For Each v In Views
      Debug.Print v.titleText
   Next
End Sub