VBA脚本保存为演示文稿

huangapple go评论62阅读模式
英文:

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(&quot;&quot;, &quot;Scalable Vector Graphics (*.svg), *.svg&quot;, , &quot;Save As SVG&quot;)
    
    If SavePath &lt;&gt; &quot;False&quot; 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(&quot;excel.application&quot;)
    
    FileFormat = 18
    
    &#39;SavePath = Application.GetSaveAsFilename(&quot;&quot;, &quot;Scalable Vector Graphics (*.svg), *.svg&quot;, , &quot;Save As SVG&quot;)
    SavePath = excelApp.GetSaveAsFilename(&quot;&quot;, &quot;Scalable Vector Graphics (*.svg), *.svg&quot;, , &quot;Save As SVG&quot;)
    
    If SavePath &lt;&gt; &quot;False&quot; Then
        ActivePresentation.SaveAs SavePath, FileFormat
    End If
End Sub

huangapple
  • 本文由 发表于 2023年7月20日 21:42:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76730515.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定