英文:
VBA script to save as in Presentation
问题
Sub SaveAsSVG()
Dim SavePath As Variant
Dim FileFormat As Integer
FileFormat = 18
SavePath = Application.GetSaveAsFilename("", "Scalable Vector Graphics (*.svg), *.svg", , "Save As SVG")
If SavePath <> "False" Then
ActivePresentation.SaveAs SavePath, FileFormat
End If
End Sub
英文:
I'm trying to create a Visual Basic script that, when called, will open a SaveAs dialog in PowerPoint file, with the svg format option pre-selected. The script must be executable by a function and work on recent versions of Microsoft Office.
I tried the following approach, but I get an error in the method:Application.GetSaveAsFilename
Sub SaveAsSVG()
Dim SavePath As Variant
Dim FileFormat As Integer
FileFormat = 18
SavePath = Application.GetSaveAsFilename("", "Scalable Vector Graphics (*.svg), *.svg", , "Save As SVG")
If SavePath <> "False" Then
ActivePresentation.SaveAs SavePath, FileFormat
End If
End Sub
答案1
得分: 1
就像John Korchok
所说,
> GetSaveAsFileName是Excel的方法,而不是PowerPoint。
如果您必须使用这个方法,那么您应该在调用这个方法之前初始化一个Excel应用程序实例,所以您的代码应该像这样,然后您将不再看到
> 在方法中的错误:Application.GetSaveAsFilename
Sub SaveAsSVG()
Dim SavePath As Variant
Dim FileFormat As Integer
Dim excelApp As Object
Set excelApp = CreateObject("excel.application")
FileFormat = 18
'SavePath = Application.GetSaveAsFilename("", "Scalable Vector Graphics (*.svg), *.svg", , "Save As SVG")
SavePath = excelApp.GetSaveAsFilename("", "Scalable Vector Graphics (*.svg), *.svg", , "Save As SVG")
If SavePath <> "False" Then
ActivePresentation.SaveAs SavePath, FileFormat
End If
End Sub
英文:
Just like John Korchok
said,
> GetSaveAsFileName is an Excel method, not PowerPoint.
If you have to use this method, then you should initiate a Excel app instance before to invoke this mothed, so your code should be like this instead, and you'll no longer to see
> an error in the method:Application.GetSaveAsFilename
Sub SaveAsSVG()
Dim SavePath As Variant
Dim FileFormat As Integer
Dim excelApp As Object
Set excelApp = CreateObject("excel.application")
FileFormat = 18
'SavePath = Application.GetSaveAsFilename("", "Scalable Vector Graphics (*.svg), *.svg", , "Save As SVG")
SavePath = excelApp.GetSaveAsFilename("", "Scalable Vector Graphics (*.svg), *.svg", , "Save As SVG")
If SavePath <> "False" Then
ActivePresentation.SaveAs SavePath, FileFormat
End If
End Sub
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论