I am trying to read through a Word document and create a user defined collection of the sentences that have revisions.
This kind of appears to work except it appears that the collection is populated with the sentence text and not a sentence range object.
I would like to then read through the returned collection and return the sentence objects, but I can only return the text. Here is the demo
It prints the text and returns a varType of 8 for a string. I would not expect that to work and I would expect an object vartype. If I try to set an item from the collection = an object variable, I get an "object required error".
It appears that
colTemp.Add snt
Is defaulting to
colTemp.add snt.text
Obviously I am missing something fundamental. Any help would be appreciated.
Code:
Public Function getChangedSentences(theDoc As Document) As Collection
Dim snt As Range
Dim colTemp As New Collection
For Each snt In theDoc.Sentences
If snt.Revisions.Count > 0 Then
colTemp.Add snt
End If
Next snt
Set getChangedSentences = colTemp
End Function
This kind of appears to work except it appears that the collection is populated with the sentence text and not a sentence range object.
I would like to then read through the returned collection and return the sentence objects, but I can only return the text. Here is the demo
Code:
Public Sub testCol()
Dim chngs As Collection
Dim snt As Object
Dim i As Integer
Set chngs = getChangedSentences(ActiveDocument)
For i = 1 To chngs.Count
Debug.Print chngs.Item(i)
Debug.Print VarType(chngs.Item(i))
'set snt = chngs.item(i)
Next i
End Sub
It prints the text and returns a varType of 8 for a string. I would not expect that to work and I would expect an object vartype. If I try to set an item from the collection = an object variable, I get an "object required error".
It appears that
colTemp.Add snt
Is defaulting to
colTemp.add snt.text
Obviously I am missing something fundamental. Any help would be appreciated.