我想使用AppleScript在PowerPoint(2011 Mac)幻灯片中更改所选文本的西方和亚洲字体设置。根据{{3}},以下内容应该有效。但是,我甚至无法获得选择的文字范围,更不用说字体的名称。
tell application "Microsoft PowerPoint"
tell active window
set name of font of text range of selection to "Palatino"
set east asian name of font of text range of selection to "YuMincho"
end tell
end tell
结果如下。
error "Can’t get text range of selection." number -1728 from «class TObj» of «class SelO»
实际上,以下会发出同样的错误。
tell application "Microsoft PowerPoint"
tell active window
get text range of selection
end tell
end tell
另一方面,以下简单的VBA代码可以正常工作。
Sub HiraginoSansW2HelveticaNeueLight()
With ActiveWindow.Selection.TextRange.Font
.Name = "Palatino"
.NameFarEast = "YuMincho"
End With
End Sub
基本上,VBA可以满足我的需要,但它涉及启用Macro并以.pptm格式而不是标准.pptx等保存。它不像AppleScript那样方便,我可以从菜单栏访问。
有人可以帮助我让AppleScrit工作吗?
答案 0 :(得分:1)
以下代码运作良好。
tell application "Microsoft PowerPoint"
tell active window
set font name of font of text range of selection of it to "Arial"
set east asian name of font of text range of selection of it to "游明朝体"
end tell
end tell
答案 1 :(得分:1)
某些命令需要指定窗口(即使在tell active window
块中)
使用its
或of it
,如下所示:
text range of selection of it
text range of its selection
Powerpoint中AppleScript术语的信息:使用font name of font
代替name of font