无法使用AppleScript在PowerPoint(Mac 2011)幻灯片中获取文本范围的选择

时间:2016-01-18 01:55:35

标签: fonts applescript powerpoint

我想使用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工作吗?

2 个答案:

答案 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块中)

使用itsof it,如下所示:

text range of selection of it
text range of its selection

Powerpoint中AppleScript术语的信息:使用font name of font代替name of font