Visio) (Application.BeginUndoScope 方法

會使用 Microsoft Visio 實例的唯一範圍識別碼來啟動交易。

語法

運算式beginUndoScope (bstrUndoScopeName)

expression 代表 Application 物件的變數。

參數

名稱 必要/選用 資料類型 描述
bstrUndoScopeName 必要 字串 範圍的名稱;可能會出現在 Visio 使用者介面中。

傳回值

Long

註解

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

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

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

注意事項

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

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

  • Microsoft.Office.Interop.Visio.IVApplication.BeginUndoScope (字串)

範例

這個範例將示範如何使用 BeginUndoScope 方法來開始進行交易,這項交易具有 Visio 實例的唯一範圍識別碼。

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