Microsoft Word Selection Types VBA (Visual Basic for Applications)

Microsoft Word Selection Types VBA (Visual Basic for Applications)


Is a property which can be validated using WdSelectionType enumeration which has following constants:

  1. wdNoSelection : Its integer value is 0, No Selection
  2. wdSelectionIP: Its integer value is 1, refers to an inline paragraph selection in a document.
  3. wdSelectionNormal: Its integer value is 2, refers to normal or user defined selection in a document
  4. wdSelectionFrame: Its integer value is 3, refers if selection within frame object
  5. wdSelectionColumn: Its integer value is 4, refers if selection is within a column in a table
  6. wdSelectionRow: Its integer value is 5, refers if selection is within a row in a able
  7. wdSelectionBlock: Its integer value is 6, refers to a block selection
  8. wdSelectionInlineShape: Its integer value is 7, if an inline shape is selected
  9. wdSelectionShape: Its integer value is 8, if selection is a shape

Code example

Public SelectionType
    'bind selection
    Dim oSelection As Selection
    Set oSelection = Selection
    'Perform check
    Select Case oSelection.Type
        Case wdSelectionNormal:
            Debug.Print "Normal selection found"
        Case wdSelectionIP:
            Debug.Print "Inline Paragraph selection found"
        Case wdSelectionFrame:
            Debug.Print "Frame selection found"
        Case wdSelectionColumn:
            Debug.Print "Column selection found"
        Case wdSelectionRow:
            Debug.Print "Row selection found"
        Case wdSelectionBlock:
            Debug.Print "Block selection found"
        Case wdSelectionInlineShape:
            Debug.Print "Inline Shape selection found"
        Case wdSelectionShape:
            Debug.Print "Shape selection found"
        Case Else
            Debug.Print "No selection found"
    End Select
    'Memory cleanup
    Set oSelection = Nothing
End If



Row selection found

Please leave your comments or queries under comment section also please do subscribe to out blogs to keep your self upto date.

Leave a Reply

Your email address will not be published. Required fields are marked *