EscapeKey
Refers to a cancel action like Extended Mode or selected columns of any table object within document. Another word Escape Key perform interruption. In this article I will provide three different code which will cover C#, VB.Net VSTO (Visual Studio Tools for Office) and VBA (Visual Basic for Applications).
Syntax
expresson.EscapeKey
expression refers to a valid selection in the document. Given example will toggle the Extended Mode property.
C# code example
private void btnEscapeKey_Click(object sender, RibbonControlEventArgs e) { //Bind selection object wordApp.Selection oSelection = Globals.ThisAddIn.Application.Selection; //Set extended mode to true oSelection.ExtendMode = true; //Check extended mode Console.Write("Extend mode is :" + oSelection.ExtendMode); //Perform escape oSelection.EscapeKey(); //Check extended mode Console.Write("Extend mode is :" + oSelection.ExtendMode); }
VB.Net code example
Private Sub btnEscapeKeyVB_Click(sender As Object, e As RibbonControlEventArgs) Handles btnEscapeKeyVB.Click 'Declare selection Dim oSelection as word.Selection 'Bind selection oSelection=oApplication.Selection 'Set extended mode to true oSelection.ExtendMode=True 'Check extended mode Console.Write("Extend mode is :" + oSelection.ExtendMode) 'Perform escape oSelection.EscapeKey() 'Check extended mode Console.Write("Extend mode is :" + oSelection.ExtendMode) End Sub
VBA code example
Public Sub EscapeKeyVBAExample() 'Declare selection variable Dim oSelection As Selection 'bind selection Set oSelection = Selection 'Set extended mode to true oSelection.ExtendMode = True 'Verify extended mode property Debug.Print "Extend mode is :" & oSelection.ExtendMode 'Cancel selection oSelection.EscapeKey 'Verify extended mode property Debug.Print "Extend mode is :" & oSelection.ExtendMode 'Memory cleanup Set oSelection = Nothing End Sub
Output
Extend mode is :True
Extend mode is :False
Please leave your comments and subscribe. Next >> Understand Page object Microsoft Word using VBA