
Private Sub UserForm_Initialize() ' 窗体加载时,清空 ListBox,填入所有打开的窗口标题 Me.ListBox1.Clear Dim win As Window For Each win In CATIA.Windows ' 添加窗口标题(通常包含文档名和视图类型) Me.ListBox1.AddItem win.Caption Next win ' 如果没有窗口,给出提示 If Me.ListBox1.ListCount = 0 Then Me.ListBox1.AddItem "(无打开的窗口)" End If End Sub |
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) ' 双击时,根据选中的标题激活对应的窗口 Dim selectedCaption As String selectedCaption = Me.ListBox1.Value If selectedCaption = "" Or selectedCaption = "(无打开的窗口)" Then Exit Sub On Error Resume Next Dim win As Window For Each win In CATIA.Windows If win.Caption = selectedCaption Then win.Activate ' 激活该窗口 End Exit For End If Next win On Error GoTo 0 End Sub |