會使用 Microsoft Visio 實例的唯一範圍識別碼來啟動交易。
語法
表情。BeginUndoScope (bstrUndoScopeName)
詞 一個代表 文件 物件的變數。
參數
| 名稱 | 必要/選用 | 資料類型 | 描述 |
|---|---|---|---|
| bstrUndoScopeName | 必要 | 字串 | 範圍的名稱;可能會出現在 Visio 使用者介面中。 |
傳回值
Long
註解
如果您需要知道接收的事件是否為已起始之特定作業的結果,請使用 BeginUndoScope 及 EndUndoScope 方法來限制作業的範圍。 在事件處理常式中,請使用 IsInScope 屬性來測試 BeginUndoScope 方法所傳回的範圍識別碼是否為目前內容的一部分。 當您收到具有該識別碼的 ExitScope 事件時,請務必要從 BeginUndoScope 屬性中清除已儲存的範圍識別碼。
你必須在呼叫 BeginUndoScope 方法與 EndUndoScope 方法的呼叫之間取得平衡。 如果你呼叫 BeginUndoScope 方法,應該在完成構成作用範圍的動作後立即呼叫 EndUndoScope 方法。 此外,雖然對多個文件的操作應該在單一範圍內保持穩健,但關閉文件可能會產生副作用,例如清除目前開放範圍的復原資訊,以及還原與重做堆疊。 若發生這種情況,將 bCommit = False 傳給 EndUndoScope 並不會還原復原資訊。
你也可以使用 BeginUndoScope 和 EndUndoScope 方法,將外掛定義的動作加入 Visio 的復原串流。 這在你操作無模式場景時非常有用,因為啟動代理是附加元件的使用者介面或無模式程式動作的一部分。
注意事項
大多數 Visio 動作已經被內部復原範圍包覆,因此應用程式內執行的外掛元件不需要呼叫這個方法。
範例
這個範例將示範如何使用 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 支援與意見反應。