gpt4 book ai didi

excel - 使用 Excel VBA 关闭 Powerpoint 对象(不使用 Powerpoint.Application)

转载 作者:行者123 更新时间:2023-12-02 07:28:27 25 4
gpt4 key购买 nike

希望有人能帮助我编写一些 VBA 代码。我使用 VBA 循环将 Excel 图表、文本框和表格粘贴到 Powerpoint 模板中。但是,由于我无法确定用户是否安装了 Powerpoint 对象库,因此我无法使用 Dim PPTApp 作为 Powerpoint.Application 类型语法。

我使用对象。效果很好。除了一件:关闭 Powerpoint。

代码:

Dim oPPTPres As Object  ' Late binding: This is a PowerPoint.Presentation but we cannot assume that the Microsoft PowerPoint 11 library will be loaded in the workbook that this module has been copied to.
Dim oPPTShape As Object ' Late binding: This is a PowerPoint.Shapebut we cannot assume that the Microsoft PowerPoint 11 library will be loaded in the workbook that this module has been copied to.


PPTFile = Range("PPTFile").value ' Read PowerPoint template file name
Set oPPTPres = GetObject(PPTFile): oPPTPres.Application.Visible = msoTrue ' Switch to or open template file

。。。.

strNewPresPath = Range("OutputFileName").value
oPPTPres.SaveAs strNewPresPath
' Range("PPTFile").value = strNewPresPath
ScreenUpdating = True
oPPTPres.Close 'Closes presentation but not Powerpoint
oPPTPres.Application.Quit 'No noticeable effect

事件演示文稿将关闭,但 Powerpoint 本身保持打开状态(没有文件窗口打开)。然后,因为它是打开的,所以当下一个运行时(我有一个循环将循环并连续执行许多这些构建),它会打开模板以及最新构建的 Powerpoint 文件,创建系统锁定问题。

有什么想法吗?

非常感谢您的帮助!

最佳答案

我不完全确定为什么你的代码不起作用。我尝试按照建议设置oPPTPres = Nothing,但这也不起作用。但是,以下方式 PowerPoint 在我的计算机上关闭

Dim oPPTPres As Object  ' Late binding: This is a PowerPoint.Presentation but we cannot assume that the Microsoft PowerPoint 11 library will be loaded in the workbook that this module has been copied to.
Dim oPPTShape As Object ' Late binding: This is a PowerPoint.Shapebut we cannot assume that the Microsoft PowerPoint 11 library will be loaded in the workbook that this module has been copied to.
Dim oPPTApp As Object

Set oPPTApp = CreateObject("PowerPoint.Application")
oPPTApp.Visible = True

Set oPPTPres = oPPTApp.Presentations.Open(PPTFile)

...

oPPTPres.Close
Set oPPTPres = Nothing
oPPTApp.Quit
Set oPPTApp = Nothing

关于excel - 使用 Excel VBA 关闭 Powerpoint 对象(不使用 Powerpoint.Application),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12163390/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com