在Excel VBA中保存PowerPoint [英] Saving a PowerPoint in Excel VBA
问题描述
我有一些代码可以创建一个新的powerpoint,其中包括来自excel文件的一些图像.我想使用字符串变量保存文件以定义其名称.我已经完成了尽职调查,没有找到成功的解决方案,这让我惊讶于基于我要完成的任务的基础.截至目前,我已经...
I have code that creates a new powerpoint consisting of some images from an excel file. I want to save the file using a string variable to define its name. I've done my due diligence searching for solutions with no success, which surprises me based on how basic of a task I'm trying to complete. As of now, I have...
newPowerPoint.ActivePresentations.SaveAs filenamestring, 1
newPowerPoint.ActivePresentations.Close
但是我不断收到大量错误消息.我在另一个模块中将newPowerPoint定义为public
But I keep getting a whole host of error messages. I have newPowerPoint defined as public in another module
Public newPowerPoint As powerpoint.Application
有什么建议吗?
推荐答案
我认为您在确定变量oPPTApp的尺寸时并未实际创建Powerpoint.Application实例.
I think you are dimensioning the variable oPPTApp without actually creating an instance of Powerpoint.Application.
Public ppApp As PowerPoint.Application
Sub PPTFile()
Dim ppPres As Presentation
Dim fileNameString As String
fileNameString = "C:\testPPT.pptx" '<change to your file path/name
'Create an instance of PPT to work with
Set ppApp = CreateObject("Powerpoint.Application")
ppApp.Visible = True
'Create a new presentation (or you can access an existing file with ppApp.Presentations.Open
Set ppPres = ppApp.Presentations.Add
'Save:
ppPres.SaveAs fileNameString, 1
'Quit the instance of PPT that you initiated above.
ppApp.Quit
End Sub
编辑
使用AddSlide方法添加幻灯片时,需要引用 CustomLayout
.
As you're adding slides using the AddSlide method, you need to refer to a CustomLayout
.
Dim sldCount As Integer
sldCount = ppPres.Slides.count
ppPres.Slides.AddSlide sldCount + 1, ppPres.Slides(sldCount).CustomLayout
'Once you've added the slide, then set using Layout:
ppPres.Slides(sldCount + 1).Layout = ppLayoutBlank
或者,您可以使用接受 Layout
参数的旧 .Add
方法,而不是 .AddSlide
(需要CustomLayout).:
Alternatively, you can use the old .Add
method which accepts the Layout
argument, instead of .AddSlide
(which requires a CustomLayout):
ppPres.Slides.Add sldCount + 1,ppLayoutBlank
这篇关于在Excel VBA中保存PowerPoint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!