使用 VBA 从 Excel 打开一个 PowerPoint 演示文稿,然后将该演示文稿设置为一个变量
Open a PowerPoint presentation from Excel with VBA and then set that presentation to a variable
我必须 post 很多 Excel 图表到特定的 PowerPoint 文档,我正在 Excel VBA 中构建一个宏来完成它我.
我能够正确打开要更新的 PowerPoint 演示文稿,但是我不知道如何将刚刚打开的演示文稿设置为名为 MyPresentation
的变量。
Dim myPresentation As PowerPoint.Presentation
Dim PowerPointApp As PowerPoint.Application
PowerPointApp.Presentations.Open Filename:="obscured filepath and name"`
显然还有一些额外的代码,但我正在尝试将我刚刚在第 3 行中打开的 Presentation 设置为 MyPresentation
变量,以便我可以引用我刚刚打开的文档。
我最终找到了 MVP Andy Pope 的解决方案。
供未来用户使用的一些相关代码片段。 (仅供参考,当我 运行 进入问题时,我的 PPT 已经可见)
Dim DestinationPPT As String
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation
'Easier to define manually set links up front so it's easier to change/modify
DestinationPPT = "C:\yourfilepath\yourfilename.pptx"`
从ExcelVBA
中查找Spreadsheet Guru打开PPT的指南
然后:
Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT)
首先要为ppt文件的使用做铺垫,
我做了什么:
Dim DestinationPPT As String
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation
Set PowerPointApp = CreateObject("PowerPoint.Application")
DestinationPPT = "path"
PowerPointApp.Presentations.Open (DestinationPPT)
这个对我有用:
'devlare variables
Dim MyPPT As Object
'create PowerPoint
Set MyPPT = CreateObject("Powerpoint.application")
'make it visible
MyPPT.Visible = True
'path to powerpoint
MyPPT.presentations.Open "path\powerpoint.pptx"
在打开之前将可见设置为真。否则它对我不起作用
我试图创建一个 excel 文件,该文件可以根据特定工作表生成预定义的 powerpoint 演示文稿,在 excel-file.
中具有不同的值
我的问题是我部门的每个人都应该能够下载 excel-file 和 运行 它。
在 vba 中定义演示文稿并不适用于所有人,因为此操作所需的引用并非在每个 computer/excel-programm 上都激活。
Createobject 帮我解决了这个问题。
这是我正在谈论的代码:
Dim pptApp as object
Dim strpath as string
strpath = ThisWorkbook.Path & "\Test_Dummy.pptx"
Set pptApp = createobject("Powerpoint.application")
pptApp.Presentations.Open Filename:=strpath, readonly:=false, untitled:=true, withwindow:=true
没有的工作是:
Dim pptApp as Powerpoint.Application
或
Dim pptApp as object
Set pptApp = New Powerpoint.Application
没有在 vba
中设置所需的引用
我必须 post 很多 Excel 图表到特定的 PowerPoint 文档,我正在 Excel VBA 中构建一个宏来完成它我.
我能够正确打开要更新的 PowerPoint 演示文稿,但是我不知道如何将刚刚打开的演示文稿设置为名为 MyPresentation
的变量。
Dim myPresentation As PowerPoint.Presentation
Dim PowerPointApp As PowerPoint.Application
PowerPointApp.Presentations.Open Filename:="obscured filepath and name"`
显然还有一些额外的代码,但我正在尝试将我刚刚在第 3 行中打开的 Presentation 设置为 MyPresentation
变量,以便我可以引用我刚刚打开的文档。
我最终找到了 MVP Andy Pope 的解决方案。
供未来用户使用的一些相关代码片段。 (仅供参考,当我 运行 进入问题时,我的 PPT 已经可见)
Dim DestinationPPT As String
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation
'Easier to define manually set links up front so it's easier to change/modify
DestinationPPT = "C:\yourfilepath\yourfilename.pptx"`
从ExcelVBA
中查找Spreadsheet Guru打开PPT的指南然后:
Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT)
首先要为ppt文件的使用做铺垫, 我做了什么:
Dim DestinationPPT As String
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation
Set PowerPointApp = CreateObject("PowerPoint.Application")
DestinationPPT = "path"
PowerPointApp.Presentations.Open (DestinationPPT)
这个对我有用:
'devlare variables
Dim MyPPT As Object
'create PowerPoint
Set MyPPT = CreateObject("Powerpoint.application")
'make it visible
MyPPT.Visible = True
'path to powerpoint
MyPPT.presentations.Open "path\powerpoint.pptx"
在打开之前将可见设置为真。否则它对我不起作用
我试图创建一个 excel 文件,该文件可以根据特定工作表生成预定义的 powerpoint 演示文稿,在 excel-file.
中具有不同的值我的问题是我部门的每个人都应该能够下载 excel-file 和 运行 它。
在 vba 中定义演示文稿并不适用于所有人,因为此操作所需的引用并非在每个 computer/excel-programm 上都激活。
Createobject 帮我解决了这个问题。 这是我正在谈论的代码:
Dim pptApp as object
Dim strpath as string
strpath = ThisWorkbook.Path & "\Test_Dummy.pptx"
Set pptApp = createobject("Powerpoint.application")
pptApp.Presentations.Open Filename:=strpath, readonly:=false, untitled:=true, withwindow:=true
没有的工作是:
Dim pptApp as Powerpoint.Application
或
Dim pptApp as object
Set pptApp = New Powerpoint.Application
没有在 vba
中设置所需的引用