do Visual Basic
не является командой AppleScript в словаре AS для Word, поэтому она не будет работать.
(Мало того, ваш код VBA в вашем примере в любом случае недопустим.)
run VB macro
является командой AS для Word, поэтому, если у вас есть макрос VBA с именем GetPage
, скажем, в вашем проекте Normal.dot
, вы можете использовать этот AppleScript для его запуска:
tell application "Microsoft Word"
run VB macro macro name "GetPage"
end tell
(ПРИМЕЧАНИЕ. Я предполагаю, что ваш код VBA будет работать в версии Word для Ma c. Я не пробовал его и исправлял, если это не было бы другим вопросом.)
Вот быстрый AppleScript, который я написал, который должен делать то, что вы хотите. Он захватывает первое слово каждой страницы и копирует их в буфер обмена. Имейте в виду, что у этого был минимальный уровень тестирования, но он работал с документом Word на 79 страниц, который у меня был.
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
to trimText:inText
set _str to current application's NSString's stringWithString:inText
set _whitespace to current application's NSCharacterSet's whitespaceAndNewlineCharacterSet()
set _str to _str's stringByTrimmingCharactersInSet:_whitespace
return _str as text
end trimText:
on run
set wordList to {}
set lastPage to false
tell application "Microsoft Word"
tell active document
set firstWord to word 1
repeat until lastPage
set pageWord to my trimText:(content of firstWord)
if pageWord ≠ "" then set end of wordList to pageWord
set nextPage to go to next firstWord what goto a page item
if (start of content of nextPage) is not equal to (start of content of firstWord) then
set firstWord to word 1 of nextPage
else
set lastPage to true
end if
end repeat
end tell
end tell
if (count of wordList) is greater than 0 then
set {oldDelims, AppleScript's text item delimiters} to {AppleScript's text item delimiters, linefeed}
set the clipboard to (wordList as text)
set AppleScript's text item delimiters to oldDelims
end if
end run