Reputation: 23
I have a VBA code running under Excel 2016 (Windows) that exports charts to a PowerPoint file (.pptx).
I am trying to make that run on MacOS.
I first rewrote the FileDialogOpen function for MacOS to browse and pick up one .pptx file to open for editing.
While opening the picked file on MacOS (Office 2016 as well), I get the following error:
It seems a PowerPoint application is started but the specified .pptx file is not loaded. I checked the file name variable is assigned to the full path filename that was picked up (including extension .pptx).
The code failing on Open.
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
Upvotes: 1
Views: 1149
Reputation: 2875
Try this:
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
Upvotes: 2
Reputation: 5805
MacScript
has been deprecated.
This article: https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/macscript-function
Points you to this article: The MacScript function is not working well in Office for Mac 2016! Any ideas?
The answer is that you need try again using AppleScriptTask
. If you get stuck there then you should open a new question with your AppleScriptTask code.
Upvotes: 0