Application.WindowActivate 方法 (Project)

用于激活窗口。

语法

expressionWindowActivate( _WindowName_, _DialogID_, _TopPane_ )

expression:表示 Application 对象的变量。

参数

名称 必需/可选 数据类型 说明
WindowName 可选 String 要激活的窗口的名称。 窗口名称即显示在窗口标题栏中的确切文本。 默认值为活动窗口的名称。
DialogID 可选 Long 指定要激活的对话框的常量。 可以是下面的 PjDialog 常量: pjResourceAssignment
TopPane 可选 Boolean 如此 如果项目应激活上部窗格。 默认值为 True

返回值

Boolean

示例

下面的示例允许用户指定并激活"热"的窗口。 如果您将 ActivateBookmarkedWindow 宏指定快捷键,您可以按该键可快速激活了书签的窗口。

Public BookmarkedWindowName As String ' The name of the current bookmarked window 
 
Sub ActivateBookmarkedWindow() 
 
 Dim IsOpen As Boolean ' Whether or not the current bookmarked window is open 
 Dim I As Long ' Index for For...Next loop 
 
 IsOpen = False ' Assume the bookmarked window is not open. 
 
 For I = 1 To Windows.Count ' Look for the current bookmarked window. 
 If LCase(Windows(I).Caption) = LCase(BookmarkedWindowName) Then 
 IsOpen = True 
 Exit For 
 End If 
 Next I 
 
 ' If the current bookmarked window is not open or defined, then run 
 ' the ChangeBookmarkedWindow procedure. 
 If Len(BookmarkedWindowName) = 0 Or Not IsOpen Then 
 MsgBox ("The current bookmarked window is not open or has not been defined.") 
 ChangeBookmarkedWindowName 
 ' If the bookmarked window is open, activate it. 
 Else 
 WindowActivate (BookmarkedWindowName) 
 End If 
 
End Sub 
 
Sub ChangeBookmarkedWindowName() 
 
 Dim Entry As String ' The text entered by the user 
 
 Entry = InputBox$("Enter the name of the bookmarked window.") 
 
 ' If the user chooses Cancel, then exit the Sub procedure. 
 If Entry = Empty Then Exit Sub 
 
 ' Otherwise, set the name of the bookmarked window and then activate it. 
 BookmarkedWindowName = Entry 
 ActivateBookmarkedWindow 
 
End Sub

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。