EndUndoScope 方法 (Visio)Application.EndUndoScope method (Visio)

结束或取消具有唯一范围的事务。Ends or cancels a transaction that has a unique scope.

语法Syntax

表达式EndUndoScope(nScopeID, bCommit)expression.EndUndoScope (nScopeID, bCommit)

expression:表示 Application 对象的变量。expression A variable that represents an Application object.

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
nScopeIDnScopeID 必需Required LongLong 要关闭的范围的 ID。The ID of the scope to close.
bCommitbCommit 必需Required BooleanBoolean 指示应接受 (True) 还是取消 (False) 在范围期间所做的更改的标志。flag indicating that the changes made during the scope should be accepted (True) or canceled (False).

返回值Return value

NothingNothing

注解Remarks

如果您需要知道您收到的事件是否是您启动的特定操作的结果, 请使用BeginUndoScopeEndUndoScope方法来包装您的操作。If you need to know whether events you receive are the result of a particular operation that you initiated, use the BeginUndoScope and EndUndoScope methods to wrap your operation. 在事件处理程序中,使用 IsInScope 属性来测试 BeginUndoScope 方法返回的范围 ID 是否为当前上下文的一部分。In your event handlers, use the IsInScope property to test whether the scope ID returned by the BeginUndoScope method is part of the current context. 当您收到具有该 ID 的 ExitScope 事件时,请确保从 BeginUndoScope 属性中清除存储的范围 ID。Make sure you clear the scope ID you stored from the BeginUndoScope property when you receive the ExitScope event with that ID.

您必须通过调用EndUndoScope方法来平衡对BeginUndoScope方法的调用。You must balance calls to the BeginUndoScope method with calls to the EndUndoScope method. 如果调用的是 BeginUndoScope 方法,则在完成构成您的范围的操作后,应该立即调用 EndUndoScope 方法。If you call the BeginUndoScope method, you should call the EndUndoScope method as soon as you are done with the actions that constitute your scope. 另外,尽管对多个文档的操作在单个范围中应该是可靠的,但是关闭文档可能会产生副作用,它会清除当前打开的范围的撤消信息并清除撤消和恢复堆栈。Also, while actions to multiple documents should be robust within a single scope, closing a document may have the side effect of clearing the undo information for the currently open scope as well as clearing the undo and redo stacks. 如果发生这种情况,将 bCommit = False 传递给 EndUndoScope 并不能恢复撤消信息。If that happens, passing bCommit = False to EndUndoScope does not restore the undo information.

您还可以使用BeginUndoScopeEndUndoScope方法将由加载项定义的操作添加到 Microsoft Visio 撤消流中。You can also use the BeginUndoScope and EndUndoScope methods to add an action defined by an add-on to the Microsoft Visio undo stream. 当您在无模式方案(其中初始化代理为加载项用户界面或无模式编程动作的一部分)中进行操作时,这很有用。This is useful when you are operating from modeless scenarios where the initiating agent is part of an add-on's user interface or a modeless programmatic action.

注释 大多数 Visio 操作已包装在内部撤消作用域中, 因此在应用程序中运行的加载项不需要调用此方法。Note Most Visio actions are already wrapped in internal undo scopes, so add-ons running within the application do not need to call this method.

如果你的 Visual Studio 解决方案包含Microsoft. Visio reference, 则此方法映射到以下类型:If your Visual Studio solution includes the Microsoft.Office.Interop.Visio reference, this method maps to the following types:

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

示例Example

此示例演示如何使用EndUndoScope方法来结束具有 Visio 实例的唯一范围 ID 的事务。This example shows how to use the EndUndoScope method to end a transaction that has a unique scope ID for an instance of 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

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.