InvisibleApp.CurrentScope 属性 (Visio)

确定引起事件触发的范围 ID。 此为只读属性。

语法

表达式CurrentScope

表达 一个代表 InvisibleApp 对象的变量。

返回值

Long

备注

如果范围没有打开,则返回 visScopeIDInvalid (-1)。 范围 ID 可以是对应于 Visio 命令的内部 Microsoft Visio 范围 ID,也可以是由 BeginUndoScope 方法传递给自动化客户机的外部范围 ID。

如果 EnterScope 事件已经触发而 ExitScope 事件却尚未触发,则事件的接收方会认为范围处于打开状态。

要确定事件队列的触发是与应用程序内部的特定范围相关,还是与自动化客户机打开或关闭的范围相关,请使用 IsInScope 属性。

示例

以下示例显示如何使用 CurrentScope 属性确定当前范围的 ID。

Private WithEvents vsoApplication As Visio.Application 
Private lngScopeID As Long 
 
Public Sub ScopeActions() 
 
 Dim vsoShape As Visio.Shape 
 
 'Set the module level application variable to 
 'trap Application level events. 
 Set vsoApplication = Application 
 
 'Begin a scope, set the module level variable. 
 lngScopeID = Application.BeginUndoScope("Draw Shapes") 
 
 'Draw three shapes. 
 Set vsoShape = ActivePage.DrawRectangle(1, 2, 2, 1) 
 ActivePage.DrawOval 3, 4, 4, 3 
 ActivePage.DrawLine 4, 5, 5, 4 
 
 'Change a cell (which would trigger a cell changed event). 
 vsoShape.Cells("Width").Formula = 5 
 
 'End and commit this scope. 
 Application.EndUndoScope lngScopeID, True 
 
End Sub 
 
Private Sub vsoApplication_CellChanged(ByVal Cell As IVCell) 
 
 'Check to see if this cell change is the result of something 
 'happening within the scope. 
 If vsoApplication.IsInScope(lngScopeID) Then 
 Debug.Print Cell.Name & " changed in scope "; lngScopeID 
 End If 
 
End Sub 
 
Private Sub vsoApplication_EnterScope(ByVal app As IVApplication, _ 
 ByVal nScopeID As Long, _ 
 ByVal bstrDescription As String) 
 
 If vsoApplication.CurrentScope = lngScopeID Then 
 Debug.Print "Entering current scope " & nScopeID 
 Else 
 Debug.Print "Enter Scope " & bstrDescription & "(" & nScopeID & ")" 
 End If 
 
End Sub 
 
Private Sub vsoApplication_ExitScope(ByVal app As IVApplication, _ 
 ByVal nScopeID As Long, _ 
 ByVal strDescription As String, _ 
 ByVal bErrOrCancelled As Boolean) 
 
 If vsoApplication.CurrentScope = lngScopeID Then 
 Debug.Print "Exiting current scope " & nScopeID 
 Else 
 Debug.Print "ExitScope " & bstrDescription & "(" & nScopeID & ")" 
 End If 
 
End Sub

支持和反馈

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