0

我正在寻找一种方法来找出放置在 MSWord 页面标题上的两个书签之间的文本内容。

假设两个书签是 BKM_1 和 BKM_2。两个书签之间的文本也是“测试”。

Local loWordApplication, loDoc, loRange
loWordApplication = CREATEOBJECT("Word.Application")
loDoc = loWordApplication.Documents.Open("C:\Example.doc")
IF loDoc.BookMarks.EXISTS("BKM_1") AND loDoc.BookMarks.EXISTS("BKM_2") 
   loRange = loDoc.RANGE(loDoc.BookMarks("BKM_1").START, loDoc.BookMarks("BKM_2").START) 
   loRange.SELECT
   ?loRange.TEXT && Printing the value here and expecting the result as "Test"
ENDIF

但是即使存在书签,上面也不会产生我正在寻找的结果。请帮忙!

4

1 回答 1

1

页眉、页脚是不同类型的故事< g > - 没有双关语:

#Define wdCharacter 1
Local loWordApplication, loDoc, loRange
loWordApplication = Createobject("Word.Application")
loDoc = loWordApplication.Documents.Open("C:\Example.doc")
If loDoc.BookMarks.Exists("BKM_1") And loDoc.BookMarks.Exists("BKM_2") And ;
        loDoc.BookMarks("BKM_1").StoryType = loDoc.BookMarks("BKM_2").StoryType
    Local lnCharacters
    lnCharacters = loDoc.BookMarks("BKM_2").Start-loDoc.BookMarks("BKM_1").Start
    If loDoc.BookMarks("BKM_1").StoryType != 1
        loDoc.StoryRanges(loDoc.BookMarks("BKM_1").StoryType).Select()
    Endif

    loDoc.BookMarks("BKM_1").Range.Select()
    loDoc.Application.Selection.Moveend(wdCharacter, m.lnCharacters)

    loRange = loWordApplication.Selection

    ?loRange.Text && Printing the value here and expecting the result as "Test"
Endif
loWordApplication.Quit
于 2012-12-05T15:56:36.283 回答