如何在 MacOS 上打开 PowerPoint 演示文稿
How to open a PowerPoint presentation on MacOS
我在 Excel 2016 (Windows) 下有一个 VBA 代码 运行ning,可将图表导出到 PowerPoint 文件 (.pptx)。
我正在尝试在 MacOS 上实现 运行。
我首先为 MacOS 重写了 FileDialogOpen 函数以浏览并选择一个 .pptx 文件打开进行编辑。
在 MacOS(以及 Office 2016)上打开选取的文件时,出现以下错误:
PowerPoint 应用程序似乎已启动,但未加载指定的 .pptx 文件。我检查了文件名变量是否分配给了拾取的完整路径文件名(包括扩展名 .pptx)。
代码打开失败。
Sub Export_Charts_To_PPT_Presentation()
Dim PptApp As PowerPoint.Application
Dim PptDoc As PowerPoint.Presentation
Set PptApp = New PowerPoint.Application
PptPresPath = FileDialogOpen
If PptPresPath = "" Then Exit Sub
Set PptDoc = PptApp.Presentations.Open(PptPresPath, WithWindow:=msoTrue)
End Sub
Function FileDialogOpen() As String
mypath = MacScript("return (path to desktop folder) as String")
sMacScript = "set applescript's text item delimiters to "","" " & vbNewLine & _
"try " & vbNewLine & _
"set theFiles to (choose file " & _
"with prompt ""Please select a file or files"" default location alias """ & _
mypath & """ multiple selections allowed false) as string" & vbNewLine & _
"set applescript's text item delimiters to """" " & vbNewLine & _
"on error errStr number errorNumber" & vbNewLine & _
"return errorNumber " & vbNewLine & _
"end try " & vbNewLine & _
"return theFiles"
FileDialogOpen = MacScript(sMacScript)
End Function
MacScript
已弃用。
将您指向这篇文章:
The MacScript function is not working well in Office for Mac 2016! Any ideas?
答案是您需要使用 AppleScriptTask
再试一次。如果你卡在那里,那么你应该用你的 AppleScriptTask 代码打开一个新问题。
试试这个:
Sub Export_Charts_To_PPT_Presentation()
Dim PptApp As PowerPoint.Application
Dim PptDoc As PowerPoint.Presentation
Dim PptPresPath As String
PptPresPath = FileDialogOpen
If PptPresPath = "" Or Right(PptPresPath, 5) <> ".pptx" Then Exit Sub
Set PptApp = New PowerPoint.Application
Set PptDoc = PptApp.Presentations.Open(PptPresPath, WithWindow:=msoTrue)
End Sub
Function FileDialogOpen() As String
Dim iPathStartPosition As Integer
mypath = MacScript("return (path to desktop folder) as String")
sMacScript = "set applescript's text item delimiters to "","" " & vbNewLine & _
"try " & vbNewLine & _
"set theFiles to (choose file " & _
"with prompt ""Please select a file or files"" default location alias """ & _
mypath & """ multiple selections allowed false) as string" & vbNewLine & _
"set applescript's text item delimiters to """" " & vbNewLine & _
"on error errStr number errorNumber" & vbNewLine & _
"return errorNumber " & vbNewLine & _
"end try " & vbNewLine & _
"return theFiles"
FileDialogOpen = Replace(MacScript(sMacScript), ":", "/")
If Val(FileDialogOpen) = -128 Then
FileDialogOpen = ""
Else
iPathStartPosition = InStr(1, FileDialogOpen, "/Users")
If iPathStartPosition > 0 Then
FileDialogOpen = Right(FileDialogOpen, Len(FileDialogOpen) - iPathStartPosition + 1)
End If
End If
End Function
我在 Excel 2016 (Windows) 下有一个 VBA 代码 运行ning,可将图表导出到 PowerPoint 文件 (.pptx)。
我正在尝试在 MacOS 上实现 运行。
我首先为 MacOS 重写了 FileDialogOpen 函数以浏览并选择一个 .pptx 文件打开进行编辑。
在 MacOS(以及 Office 2016)上打开选取的文件时,出现以下错误:
PowerPoint 应用程序似乎已启动,但未加载指定的 .pptx 文件。我检查了文件名变量是否分配给了拾取的完整路径文件名(包括扩展名 .pptx)。
代码打开失败。
Sub Export_Charts_To_PPT_Presentation()
Dim PptApp As PowerPoint.Application
Dim PptDoc As PowerPoint.Presentation
Set PptApp = New PowerPoint.Application
PptPresPath = FileDialogOpen
If PptPresPath = "" Then Exit Sub
Set PptDoc = PptApp.Presentations.Open(PptPresPath, WithWindow:=msoTrue)
End Sub
Function FileDialogOpen() As String
mypath = MacScript("return (path to desktop folder) as String")
sMacScript = "set applescript's text item delimiters to "","" " & vbNewLine & _
"try " & vbNewLine & _
"set theFiles to (choose file " & _
"with prompt ""Please select a file or files"" default location alias """ & _
mypath & """ multiple selections allowed false) as string" & vbNewLine & _
"set applescript's text item delimiters to """" " & vbNewLine & _
"on error errStr number errorNumber" & vbNewLine & _
"return errorNumber " & vbNewLine & _
"end try " & vbNewLine & _
"return theFiles"
FileDialogOpen = MacScript(sMacScript)
End Function
MacScript
已弃用。
将您指向这篇文章: The MacScript function is not working well in Office for Mac 2016! Any ideas?
答案是您需要使用 AppleScriptTask
再试一次。如果你卡在那里,那么你应该用你的 AppleScriptTask 代码打开一个新问题。
试试这个:
Sub Export_Charts_To_PPT_Presentation()
Dim PptApp As PowerPoint.Application
Dim PptDoc As PowerPoint.Presentation
Dim PptPresPath As String
PptPresPath = FileDialogOpen
If PptPresPath = "" Or Right(PptPresPath, 5) <> ".pptx" Then Exit Sub
Set PptApp = New PowerPoint.Application
Set PptDoc = PptApp.Presentations.Open(PptPresPath, WithWindow:=msoTrue)
End Sub
Function FileDialogOpen() As String
Dim iPathStartPosition As Integer
mypath = MacScript("return (path to desktop folder) as String")
sMacScript = "set applescript's text item delimiters to "","" " & vbNewLine & _
"try " & vbNewLine & _
"set theFiles to (choose file " & _
"with prompt ""Please select a file or files"" default location alias """ & _
mypath & """ multiple selections allowed false) as string" & vbNewLine & _
"set applescript's text item delimiters to """" " & vbNewLine & _
"on error errStr number errorNumber" & vbNewLine & _
"return errorNumber " & vbNewLine & _
"end try " & vbNewLine & _
"return theFiles"
FileDialogOpen = Replace(MacScript(sMacScript), ":", "/")
If Val(FileDialogOpen) = -128 Then
FileDialogOpen = ""
Else
iPathStartPosition = InStr(1, FileDialogOpen, "/Users")
If iPathStartPosition > 0 Then
FileDialogOpen = Right(FileDialogOpen, Len(FileDialogOpen) - iPathStartPosition + 1)
End If
End If
End Function