excel - VBA-自动将图表和表格复制到ppt
问题描述
我正在编写一些代码来自动将一些图表从excel复制到ppt。我面临的第一个问题是变量声明
Dim newPowerPoint As PowerPoint.Application
Dim activeSlide As PowerPoint.Slide
错误是“未定义用户定义类型”。只是为了让你知道我对这个 VBA 很陌生,所以一些描述性的评论会很有帮助。
解决方案
您得到的错误是因为您的 powerpoint 变量希望被定义为对象,并且稍后将对象设置为 powerpoint 应用程序。
Sub ChartX2P()
Dim PowerPointApp As Object
Dim myPresentation As Object
Dim mySlide As Object
Dim myShape As Object
If ActiveChart Is Nothing Then
MsgBox "Hey, please select a chart first."
Exit Sub
End If
If PowerPointApp Is Nothing Then _
Set PowerPointApp = CreateObject(class:="PowerPoint.Application")
On Error GoTo 0
Application.ScreenUpdating = False
'this will create a new powerpoint for your chart
Set myPresentation = PowerPointApp.Presentations.Add
'this will open an old powerpoint up, just change "File address" to the address
'Set myPresentation = PowerPointApp.Presentations.Open(Filename:="FileAddress")
Set mySlide = myPresentation.Slides.Add(1, 11) '11 = ppLayoutTitleOnly
ActiveChart.ChartArea.Copy
mySlide.Shapes.Paste
Set myShape = mySlide.Shapes(mySlide.Shapes.Count)
myShape.Left = 200
myShape.Top = 200
PowerPointApp.Visible = True
PowerPointApp.Activate
Application.CutCopyMode = False
End Sub
这是从这里获取的,但它看起来很简单,如果您无法从该站点获得任何信息,请告诉我
推荐阅读
- python - 从屏幕传递信息
- laravel - 使用 bootstrap 和 onEachSide 在 Laravel 的分页中添加链接
- c++ - C ++如何制作.cfg文件的根
- sql - 如何在while循环内从shell脚本运行插入语句到oracle DB
- javascript - Livewire 更新后隐藏元素
- excel - Microsoft Project - 从 Excel 电子表格导入资源费率
- javascript - HTML 无法向 Firebase 发送数据
- reactjs - .net核心反应主从形式
- react-native - Expo 模块核心依赖.platformns.ios 必须是对象类型
- docker - 使用 maven 项目的 Jenkins 管道