Visio) (Application.EnterScope 事件

在內部命令開始時,或當自動化用戶端使用 BeginUndoScope 方法開啟範圍時排入佇列。

語法

運算式EnterScope (appnScopeIDbstrDescription)

expression 代表 Application 物件的變數。

參數

名稱 必要/選用 資料類型 描述
應用程式 必要 [IVAPPLICATION] 包含該範圍的 Microsoft Visio 執行個體。
nScopeID 必要 Long 與語言無關的數位,描述剛結束的作業,或 BeginUndoScope 方法傳回的範圍識別碼。
bstrDescription 必要 字串 在不同語言版本中會變更的操作文字說明。 內含 Visio 操作的使用者介面說明,或是傳送至 BeginUndoScope 方法的說明。

註解

在 Visio 作業的情況下傳回的 nScopeID 值相當於以 visCmd開頭的命令相關常數。

如果您是使用 Microsoft Visual Basic 或 Visual Basic for Applications (VBA),則本主題中的語法會描述有效處理事件的常用方式。

如果您想要建立自己的 Event 物件,請使用 AddAddAdvise 方法。

若要建立可以執行附加元件的 Event 物件,可使用 Add 方法,因為它可適用於 EventList 集合。

若要建立用於接收通知的 Event 物件,則使用 AddAdvise 方法。

若要尋找您要建立之事件的事件代碼,請參閱 事件代碼

如果您用來處理此事件的程式是透過連線來接收使用 AddAdvise 方法所建立的通知,EnterScope 事件就是所選一組事件中的其中一個事件,這些事件會在 Application 物件的 EventInfo 屬性中記錄其他詳細資訊。

EventInfo屬性會傳回bstrDescription,如先前所述。 此外,VisEventProcvarMoreInfo引數包含格式如下的字串: [<nScopeID>;<bErrOrCancelled>;<bstrDescription>;<nHwndContext>] ,其中nHwndCoNtext是視窗的視窗控制碼 (HWND) 是命令的內容;nHwndCoNtext可以是 0。

如果是 EnterScopebErrOrCancelled 一定會等於零。

範例

這個範例會顯示如何使用 EnterScope 事件。 此範例會判斷處理 CellChanged 事件之程式的呼叫是否在特定範圍中;也就是說,該範圍的 EnterScopeExitScope 事件之間是否發生呼叫。

Private WithEvents vsoApplication As Visio.Application 
 
Private lngScopeID As Long 
 
Public Sub Scope_Example() 
 
 Dim vsoShape As Visio.Shape 
 
 'Set the module-level application variable to 
 'trap application-level events. 
 Set vsoApplication = Application 
 
 'Begin a scope. 
 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 (to trigger a CellChanged 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 my 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 bstrDescription As String, _ 
 ByVal bErrOrCancelled As Boolean) 
 
 If vsoApplication.CurrentScope = lngScopeID Then 
 Debug.Print "Exiting my scope " & nScopeID 
 Else 
 Debug.Print "Exit Scope " & bstrDescription & "(" & nScopeID & ")" 
 End If 
 
End Sub

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應