![](/img/trans.png)
[英]How to open embedded excel sheet in Powerpoint presentation using c#
[英]How to open a PowerPoint presentation on MacOS
我有一個 VBA 代碼在 Excel 2016 (Windows) 下運行,可將圖表導出到 PowerPoint 文件 (.pptx)。
我正在嘗試讓它在 MacOS 上運行。
我首先為 MacOS 重寫了 FileDialogOpen function 以瀏覽並選擇一個.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
嘗試這個:
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
MacScript
已被棄用。
將您指向這篇文章: MacScript function 在 Office for Mac 2016 中無法正常運行? 有任何想法嗎?
答案是您需要使用AppleScriptTask
再試一次。 如果您卡在那里,那么您應該使用您的 AppleScriptTask 代碼打開一個新問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.