This documentation is archived and is not being maintained.

Close Method (UndoContext Object)

Visual Studio .NET 2003

Ends an undo operation.

[Visual Basic .NET]
Public Sub Close() 
[Visual Basic 6]
Sub Close() 
HRESULT __stdcall Close();
void Close();
[JScript .NET]
public function Close()


If there are pending references to the UndoContext object, then Close aborts the operation and raises an error. An error occurs if the UndoContext object is not open when Close is called.


This example removes all newline characters from a block of selected text:

Sub RemoveNewLines()
   ' Before running, select text in an open document.
   Dim txtSel As TextSelection
   Dim strTS As String, boolWasOpen As Boolean
   txtSel = DTE.ActiveDocument.Selection
   strTS = txtSel.Text

   ' Check to see if UndoContext object is already open.
   If DTE.UndoContext.IsOpen = True Then
      boolWasOpen = True
      ' Open the UndoContext object to track changes.
      DTE.UndoContext.Open("RemoveNewLines", False)
   End If

   ' Perform search for newline characters and remove them.
   If strTS <> "" Then
      strTS = Replace(strTS, vbNewLine, "", Compare:=vbTextCompare)
   End If

   ' If UndoContext was already open, don't close it.
   If boolWasOpen = False Then
      ' Close the UndoContext object to commit the changes.
   End If
End Sub

See Also

Open Method (UndoContext Object)

Applies To: UndoContext Object