无法使用 AppleScript 在 PowerPoint (Mac 2011) 幻灯片中获取文本选择范围
Cannot get text range of selection in a PowerPoint (Mac 2011) slide with AppleScript
我想使用 AppleScript 更改 PowerPoint (2011 Mac) 幻灯片中所选文本的西方和亚洲字体设置。根据 this,像下面这样的东西应该可以工作。但是,我什至无法获得 text range of selection,更不用说 name of 字体.
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 正常工作?
以下代码运行良好。
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
一些命令需要指定 window(即使在 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
我想使用 AppleScript 更改 PowerPoint (2011 Mac) 幻灯片中所选文本的西方和亚洲字体设置。根据 this,像下面这样的东西应该可以工作。但是,我什至无法获得 text range of selection,更不用说 name of 字体.
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 正常工作?
以下代码运行良好。
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
一些命令需要指定 window(即使在 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