我不相信您拥有的对象具有 .Text 属性。选择具有 .Text 属性。尝试这个:
Sub FindHeadings()
' October 28, 2014
Dim blnFound As Boolean
Dim i As Integer
i = 1
' Set up the find conditions
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("Heading 1")
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, count:=1
'Repeat while you find the style
blnFound = True
While blnFound
With Selection.Find
.Execute
If .Found = True Then
Debug.Print i & " " & Selection.Text
i = i + 1
' Move to the next character
Selection.MoveRight Unit:=wdCharacter, count:=1
Else
Debug.Print "Done"
blnFound = False
End If
End With
Wend
End Sub