Applescript 与 MS Word:使用现有书签创建和选择范围

问题描述 投票:0回答:1

试图找出如何通过 Applescript 来做到这一点。

这是我得到的代码:

tell application "Microsoft Word"

   set myRange to create range active document ¬
       start (start of content of text object of bookmark "begin_001") ¬
       end (start of content of text object of bookmark "end_001")
   select myRange

end tell

它运行,但似乎什么也没做(没有选择)。

我已仔细检查书签是否存在并在它们之间包含文本。

我找到了可以轻松完成此操作的 VBA 代码,但想坚持使用 Applescript。

完成此操作的正确语法是什么?

vba ms-word range applescript bookmarks
1个回答
0
投票

一种方法:

tell application "Microsoft Word"
    set myRange to (create range active document start (start of bookmark of bookmark "begin_001" of active document) end (end of bookmark of bookmark "end_001" of active document))
    select myRange
end tell

另一种方式:

tell application "Microsoft Word"
    tell active document
        set myRange to (create range start (start of bookmark of bookmark "begin_001") end (end of bookmark of bookmark "end_001"))
        select myRange
    end tell
end tell

我还没有尝试验证这一点,但在 Word 2004 和 Word 2011 之间,Word 的 AppleScript 词汇表发生了很多变化。您可能已经找到了一个依赖于旧词汇表的示例。

顺便说一句,我会非常小心地使用 AppleScript 来引用不在主文档正文中的范围。 AFAICR,你可以在 VBA 中做到这一点,但你可能希望在 AppleScript 中等效的东西却行不通。

© www.soinside.com 2019 - 2024. All rights reserved.