Visio) (Application.EndUndoScope 方法

結束或取消具有唯一範圍的交易。

語法

運算式EndUndoScope (nScopeIDbCommit)

expression 代表 Application 物件的變數。

參數

名稱 必要/選用 資料類型 描述
nScopeID 必要 Long 要關閉之範圍的識別碼。
bCommit 必要 布林值 旗標,表示應接受範圍期間所做的變更, (True) 或取消 (False) 。

傳回值

註解

如果您需要知道接收的事件是否為已起始之特定作業的結果,請使用 BeginUndoScopeEndUndoScope 方法來限制作業的範圍。 在事件處理常式中,請使用 IsInScope 屬性來測試 BeginUndoScope 方法所傳回的範圍識別碼是否為目前內容的一部分。 當您收到具有該識別碼的ExitScope事件時,請務必清除您從BeginUndoScope屬性儲存的範圍識別碼。

您必須平衡 BeginUndoScope 方法的呼叫與 EndUndoScope 方法的呼叫。 如果您呼叫 BeginUndoScope 方法,您應該在完成構成範圍的動作時立即呼叫 EndUndoScope 方法。 此外,雖然對多個檔的動作應該在單一範圍內健全,但是關閉檔可能會有清除目前已開啟之範圍的復原資訊,以及清除復原和重做堆疊的副作用。 如果發生這種情況,將bCommit = False傳遞至EndUndoScope並不會還原復原資訊。

您也可以使用 BeginUndoScopeEndUndoScope 方法,將附加元件所定義的動作新增至 Microsoft Visio 復原資料流程。 當您從啟動代理程式是附加元件使用者介面或非模式程式設計動作一部分的非模式案例中操作時,這會很有用。

注意事項

大部分的 Visio 動作都已包裝在內部復原範圍中,因此在應用程式內執行的附加元件不需要呼叫此方法。

如果您的 Visual Studio 解決方案包含 Microsoft.Office.Interop.Visio 參考,此方法會對應至下列類型:

  • Microsoft.Office.Interop.Visio.IVApplication.EndUndoScope (int, bool)

範例

這個範例將示範如何使用 EndUndoScope 方法來結束交易,這項交易具有 Visio 實例的唯一範圍識別碼。

 
Private WithEvents vsoApplication As Visio.Application  
Private lngScopeID As Long 
     
Public Sub EndUndoScope_Example()  
 
    Dim vsoShape As Visio.Shape  
 
    'Set the module-level application variable to  
    'trap Application-level events.  
    Set vsoApplication = Visio.Application  
 
    'Begin a scope and set the module-level variable.  
    lngScopeID = vsoApplication.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.  
    vsoApplication.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 支援與意見反應