Visio) (Application.CurrentScope 屬性
判斷導致事件觸發的範圍之識別碼。 唯讀。
語法
運算式。CurrentScope
expression 代表 Application 物件的變數。
傳回值
Long
註解
如果未開啟範圍,會傳回 visScopeIDInvalid (-1)。 範圍識別碼可能是內部 Microsoft Visio 範圍識別碼,而此 Visio 範圍識別碼會對應到 Visio 命令或由 BeginUndoScope 方法傳遞給自動化用戶端的外部範圍識別碼。
如果已經引發 EnterScope 事件,但是尚未引發 ExitScope 事件,則事件的接收者會將範圍視為已開啟。
若要判斷事件佇列的引發是否與應用程式內部的特定範圍有關,或是與自動化用戶端所開啟及關閉的範圍有關,請使用 IsInScope 屬性。
範例
這個範例將示範如何使用 CurrentScope 屬性來判斷目前範圍的識別碼。
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 支援與意見反應。