Information
a widely used property to determine selection type information within a Selection or a Range. Followings are the constants derived from WdInformation enum which can be validated with Information property:
- wdActiveEndAdjustedPageNumber: It returns the number of the page that contains active boundary of the given selection or range in a document. Can be represented using 1
- wdActiveEndPageNumber: It returns the number of the page that contains the active boundary of the given selection or range in a document, counting from the beginning of the document. Can be represented using 3
- wdActiveEndSectionNumber: It returns the number of the section that contains the active boundary of the given selection or range in a document. Can be represented using 2
- wdAtEndOfRowMarker: it returns boolean True if the specified selection or range is at the end of row in a table. Can be represented using 2
- wdCapsLock: it returns boolean True if Caps Lock button of keyboard is ON. Can be represented using 21
- wdEndOfRangeColumnNumber: It returns column number of a table that contains the end of the given selection or range in a document. Can be represented using 17
- wdEndOfRangeRowNumber: It returns row number of a table that contains the end of the given selection or range. It can be represented using 14
- wdFirstCharacterColumnNumber: It returns position of the character in the given selection or range. Can be represented using 9
- wdFirstCharacterLineNumber: It returns position of first character in the given selection or range in a document. Can be represented using 10
- wdFrameIsSelected: It returns a boolean True if the selection or range is made to full frame or text box. Can be represented using 11
- wdHeaderFooterType: It returns header or footer type value that contains the given selection or range. Can be represented using 33
- wdHorizontalPositionRelativeToPage: It returns horizontal position of the given selection or range. Can be represented using 5
- wdHorizontalPositionRelativeToTextBoundary: It returns relative horizontal position of the given selection or range which is close to left edge of the closest text boundary enclosing it. Can be represented using 7
- wdInBibliography: It returns a boolean True if the given selection or range is in a bibliography. Can be represented using 42
- wdInCitation: It returns a boolean True if given selection or range is in a citation. Can be represented using 43
- wdInClipboard: It reference to clipboard object. Can be represented using 38
- wdInCommentPane: It returns a boolean True if given selection or range is in a comment pane area. Can be represented using 26
- wdInContentControl: It returns a boolean True if given selection or range is within content control. Can be represented using 46
- wdInCoverPage: it returns a boolean True if given selection or range is on the cover page of the document. Can be represented using 41
- wdInEndnote: It returns a boolean True if given selection or range is in an endnote area section in a document. Can be represented using 36
- wdInFieldCode: It returns a boolean True if given selection or range is in a field. Can be represented using 44
- wdInFieldResult: it returns a boolean True if given selection or range is in a field result section. Can be represented using 45
- wdInFootnote: it returns a boolean True if given selection or range is in a Footnote area section of a document. Can be represented using 45
- wdInFootnoteEndnotePane: It returns a boolean True if given selection or range is in the footnote or EndNote Pane. Can be represented using 25
- wdInHeaderFooter: It returns a boolean True if the selection or range is in the header or footer pane or in a header or footer section. Can be represented using 28
- wdInMasterDocument: It returns a boolean True if the selection or range is in a master document means document should contain at least one sub-document. Can be represented using 34
- wdInWordMail: It returns a boolean True if the selection or range is in the Mail section. Can be represented using 37
- wdMaximumNumberOfColumns: It returns highest column number of a table. Can be represented using 18
- wdMaximumNumberOfRows: It returns highest row number in a table. Can be represented using 15
- wdNumberOfPagesInDocument: It returns total number of pages available in a document. Can be represented using 4
- wdNumLock: It returns boolean True if Number Lock is ON in the keyboard. Can be represented using 22
- wdReferenceOfType: It returns relation with footnote or endnote. Can be represented using 32
- wdOverType: It returns boolean True if Overtype mode is ON. Can be represented using 23
- wdRevisionMarking: It check if track revision in the document is in effect or not. Can be represented using 24
- wdSelectionMode: It can be used to track current selection mode in a document. Can be represented using 20
- wdStartOfRangeColumnNumber: It returns the column number of a table that contains in the starting of the selection or range. Can be represented using 16
- wdStartOfRangeRowNumber: It returns the row number of a table that contains in the starting of the selection or range. Can be represented using 13
- wdVerticalPositionRelativeToPage: It returns relative vertical position of the selection or range. Can be represented using 6
- wdVerticalPositionRelativeToTextBoundary: It returns relative vertical position of the selection or range. Can be represented using 8
- wdWithInTable: It returns a boolean True if the selection is within table. Can be represented using 12
- wdZoomPercentage: It returns the current percentage of magnification in the document. Can be represented using 19
VBA Selection within table
Public Function CheckSelectionIsTable() As Boolean 'Declare variable to bind selection Dim oSelection As Selection 'Bind Selection Set oSelection = Selection If Selection.Information(wdWithInTable) = True Then MsgBox "Selection is in Table" Else MsgBox "Not a table" End If End Function
VBA Number of rows in a table:
Public Function CheckTotalNumberOfRowsInTable() As Boolean 'Declare variable to bind selection Dim oSelection As Selection 'Bind Selection Set oSelection = Selection If Selection.Information(wdWithInTable) = True Then MsgBox Selection.Information(wdMaximumNumberOfRows) Else MsgBox "No table to perform action" End If End Function
Output

C# Selection within Table:
private void btnCheckTableSelection_Click(object sender, RibbonControlEventArgs e) { //Bind selection object wordApp.Selection oSelection = Globals.ThisAddIn.Application.Selection; //Check if selection within table if (Convert.ToBoolean(oSelection.Information[wordApp.WdInformation.wdWithInTable])==true) { MessageBox.Show("Selection is in Table"); } else { MessageBox.Show("Selection not in a table"); } }
C# Number of rows in a Table
private void btnShowTotalRows_Click(object sender, RibbonControlEventArgs e) { //Bind selection object wordApp.Selection oSelection = Globals.ThisAddIn.Application.Selection; if (Convert.ToBoolean(oSelection.Information[wordApp.WdInformation.wdWithInTable])==true) { MessageBox.Show(Convert.ToInt32(oSelection.Information[wordApp.WdInformation.wdMaximumNumberOfRows]).ToString()); } else { MessageBox.Show("No table to perform action"); } }
VB.Net Selection within table:
Private Sub btnSelectionInTable_Click(sender As Object, e As RibbonControlEventArgs) Handles btnSelectionInTable.Click 'Declare variable to bind selection Dim oSelection As word.Selection 'Bind Selection oSelection = Globals.ThisAddin.Application.Selection 'Check if selection within table If oSelection.Information(WdInformation.wdWithInTable) = True Then MsgBox "Selection is in Table" Else MsgBox "Not a table" End If End Sub
VB.Net Number of rows in a table:
Private Sub btnNumberOfRowsInfo_Click(sender As Object, e As RibbonControlEventArgs) Handles btnNumberOfRowsInfo.Click 'Declare variable to bind selection Dim oSelection As word.Selection 'Bind Selection oSelection = Globals.ThisAddin.Application.Selection 'Verify selection in table If oSelection.Information(WdInformation.wdWithInTable) = True Then MsgBox oSelection.Information(WdInformation.wdMaximumNumberOfRows) Else MsgBox "No table to perform action" End If End Sub
Please leave your comments or queries under comment section also please do subscribe to out blogs to keep your self upto date.