
Sub FindHeadingStyle()
With Selection.Find
.ClearFormatting
.Style = wdStyleHeading1
.Execute FindText:="", Format:=True, _
Forward:=True, Wrap:=wdFindStop
If .Found = True Then MsgBox Selection.Text
End With
End Sub
下列指令返回并显示选定的文本。
Sub ShowSelection()
Dim strText As String
strText = Selection.Text
MsgBox strText
End Sub
下列示例返回活动文档中的第一个单词。Words 集合中的每一项是代表一个单词的 Range 对象。
Sub ShowFirstWord()
Dim strFirstWord As String
strFirstWord = ActiveDocument.Words(1).Text
MsgBox strFirstWord
End Sub
下列示例返回与活动文档中第一个书签相关联的文本。
Sub ShowFirstBookmark()
Dim strBookmark As String
If ActiveDocument.Bookmarks.Count > 0 Then
strBookmark = ActiveDocument.Bookmarks(1).Range.Text
MsgBox strBookmark
End If
End Sub