Ms word Applescript-如何在Microsoft word中获取单词的文本范围

Ms word Applescript-如何在Microsoft word中获取单词的文本范围,ms-word,applescript,Ms Word,Applescript,例如 我正在尝试通过“创建新超链接”获取文本范围,以便将单词转换为链接。这对我使用最新版本的Mac OS Sierra很有效 请尝试此版本以使用单词编号 tell application "Microsoft Word" tell active document set theRange to text range of word 5 of content of text object ... end tell end tell 或 请尝试此版

例如


我正在尝试通过“创建新超链接”获取文本范围,以便将单词转换为链接。

这对我使用最新版本的Mac OS Sierra很有效

请尝试此版本以使用单词编号

tell application "Microsoft Word"
    tell active document
        set theRange to text range of word 5 of content of text object
        ...
     end tell
end tell

请尝试此版本以使用文档中的当前选择

chosenWord(5)

on chosenWord(wordNumber)
    tell application "Microsoft Word"
        tell its document 1
            set theWord to content of word wordNumber
            tell its word wordNumber
                set {theStartOfRange, theEndOfRange} to {start of content, end of content}
                set theRange to ("The Character Range Is " & (theStartOfRange as text) & " thru " & (theEndOfRange as text))
            end tell
        end tell
    end tell
end chosenWord

我们是否可以使用appleScript从Safari和Mail中获取所选文本的范围?
tell application "Microsoft Word"
    set theSelection to content of words of selection
    set {selectionStart, selectionEnd} to ¬
        {selection start of selection, selection end of selection}
    set theRange to selectionStart & selectionEnd
end tell
return theRange