Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA + Word: Is my current paragraph deleted?

Status
Not open for further replies.

hbaake

Programmer
Jun 25, 2001
19
NL
Hi!

When MSWord change tracking is ON, is there a way in VBA to determine if my current cursor position is inside a deleted paragraph?

Thanks in advance,
Hugo.
 
Sort of. You can detect if there has been a deletion in the current paragraph. However, the value is set for the paragraph even if only part of the paragraph is deleted.

In other words, if one word has been deleted from the paragraph, or if the whole paragraph is marked deleted, the following will return the message "Deleted". If one word has been inserted, then the paragraph revision property is set as type inserted. This is kind of thrown together, but hopefully it may help to point you towards something better.

Code:
Sub DetectParaRevision()
Dim myRev As Revision
Dim r As Range

Selection.Expand unit:=wdParagraph
Set r = Selection.Range
On Error GoTo NotRevised
Set myRev = r.Revisions.Item(1)
    If Not (myRev Is Nothing) Then
        Select Case myRev.Type
            Case 1
                MsgBox "Inserted"
            Case 2
                MsgBox "Deleted"
            Case 3
                MsgBox "Formatted"
            Case Else
                MsgBox "Huh?"
        End Select
    End If
    Set r = Nothing
    Selection.Collapse Direction:=wdCollapseStart
    Exit Sub
NotRevised:
    Set r = Nothing
    Selection.Collapse Direction:=wdCollapseStart
    MsgBox "Selection point is not in a revised selection or paragraph."
End Sub

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top