Excel Vba:在Word文档上的表之前查找书签

时间:2017-07-18 19:57:14

标签: vba ms-word word-vba

是否有找到word文档上指定表之前存在的书签?

1 个答案:

答案 0 :(得分:1)

您可以使用书签StartEnd(范围)属性来获取书签的排序。

Public Sub TestIt()

    Dim bm1 As Bookmark
    Dim bm2 As Bookmark

    Set bm1 = ActiveDocument.Bookmarks("Bookmark1")
    Set bm2 = ActiveDocument.Bookmarks("Bookmark2")

    If bm1.Start < bm2.Start Then
        MsgBox "bm1 is before bm2"
    ElseIf bm1.Start > bm2.Start Then
        MsgBox "bm2 is before bm1"
    Else
        MsgBox "bm1 and bm2 start at the same place"
    End If
End Sub