I would like to be able to identify when two interop variable objects refer to the same \"actual\" object. By \"actual\", I mean for example a given paragraph o
There are various ways this could be accomplished in Word. A fairly straight-forward way is to compare the Range
properties using the InRange
method. For example:
Sub Tests()
Dim WordApp as Word.Application = Globals.ThisAddIn.Application
Dim ThisDoc as Word.Document = WordApp.ActiveDocument
Dim ThisSelection As Word.Selection = WordApp.Selection
If ThisSelection.Range Is Nothing Then Exit Sub
Dim SelectedPara As Word.Range = ThisSelection.Range.Paragraphs.First.Range
For Each MyPara As Word.Paragraph In ThisDoc.Paragraphs
Dim rng as Word.Range = myPara.Range
If rng.InRange(SelectedPara) And SelectedPara.InRange(rng) Then
'They're the same
Else
'They're not the same
End If
rng = Nothing
Next
End Sub