Word 2004找出/替换上的Applescript

时间:2013-08-02 17:20:06

标签: macos replace ms-word applescript

我正在尝试通过Word 2004文件上的Applescript运行查找/替换。在iMac上,使用OS 10.6.8。

示例代码:

tell application "Microsoft Word"
activate
set myText to text object of selection
set myFind to find object of myText
clear formatting myFind
set italic of font object of myFind to true
set content of myFind to ""
clear formatting replacement of myFind
set content of replacement of myFind to "<I>^&</I>"
execute find myFind replace replace all
end tell

每当我尝试运行此代码时,脚本会冻结到“清除格式化...”行的那一刻。 Applescript吐出以下错误:

  

错误“Microsoft Word出错:AppleEvent超时。”编号-1712

有没有人有任何想法如何解决这个问题(除了切换到Word 2008/2011等,因为我现在被迫与2004合作)?

1 个答案:

答案 0 :(得分:0)

这只是一个猜测......看起来这条线应该有“of”。当您“清除格式化替换”时,您的代码中的类似语句中有“of”。

clear formatting of myFind

如果这不起作用,你可以试试......

tell myFind to clear formatting

同样,我只是猜测我不使用Word。