共用方式為


Visio) (Application.ExitScope 事件

當內部命令結束,或是自動化用戶端使用 EndUndoScope 方法結束範圍時,就會進入佇列。

語法

運算式ExitScope (appnScopeIDbstrDescriptionbErrOrCancelled)

expression 代表 Application 物件的變數。

參數

名稱 必要/選用 資料類型 描述
應用程式 必要 [IVAPPLICATION] 包含該範圍的 Microsoft Visio 執行個體。
nScopeID 必要 Long 說明作業剛結束的編號 (與語言無關),也就是 BeginUndoScope 方法所傳回的範圍識別碼。
bstrDescription 必要 字串 在不同語言版本中會變更的操作文字說明。 內含 Visio 操作的使用者介面說明,或是傳送至 BeginUndoScope 方法的說明。
bErrOrCancelled 必要 布林值 如果範圍內發生錯誤,或是取消範圍,則為 True,如果其中沒有錯誤,也沒有取消範圍,則為 False

註解

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

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

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

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

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

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

如果您要從透過使用AddAdvise 方法建立的連線接收通知的程式處理此事件,ExitScope事件是一組選取的事件,可在Application物件的EventInfo屬性中記錄額外的資訊。

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

ExitScope 而言,如果操作失敗或取消,bErrOrCancelled 就會是零以外的值。

範例

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

 
Private WithEvents vsoApplication As Visio.Application 
Private lngScopeID AsLong 
 
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 支援與意見反應