刷新powerpoint图表使用VB优秀数据库 [英] Refreshing powerpoint charts havin excel database using VB

查看:119
本文介绍了刷新powerpoint图表使用VB优秀数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Power point演示文稿,其中有图表,其中包含excel表格中的数据库。

i在VBA中插入代码,但每当我运行代码时......每次新幻灯片出现变化时,我希望自动化我现有的幻灯片,就像在excel中发生任何更改一样,ppt应该自动刷新。在VBA中完成编码..







Sub CreatePowerPoint()



'通过以下方式添加对Microsoft PowerPoint Library的引用:

'1。转到VBA菜单中的工具

'2。点击参考文献

'3。向下滚动到Microsoft PowerPoint X.0对象库,选中复选框,然后按Okay



'首先我们声明将要使用的变量

Dim newPowerPoint As PowerPoint.Application

Dim activeSlide As PowerPoint.Slide

Dim cht As Excel.ChartObject



'查找现有实例

On Error Resume Next

设置newPowerPoint = GetObject(,"PowerPoint.Application")
$
On Error GoTo 0



'让我们创建一个新的PowerPoint

如果newPowerPoint什么都没有那么
b $ b设置newPowerPoint =新PowerPoint .Application

结束如果

'在PowerPoint中做演示文稿

如果newPowerPoint.Presentations.Count = 0那么

newPowerPoint.Presentations.Add

结束如果



'显示PowerPoint

newPowerPoint.Visible = True



'循环浏览Excel工作表中的每个图表并将其粘贴到Powe中rPoint

For Each cht In ActiveSheet.ChartObjects



'添加一张新幻灯片,我们将粘贴图表

newPowerPoint.ActivePresentation.Slides.Add newPowerPoint.ActivePresentation.Slides.Count + 1,ppLayoutText

newPowerPoint.ActiveWindow.View.GotoSlide newPowerPoint.ActivePresentation.Slides.Count

Set activeSlide = newPowerPoint.ActivePresentation.Slides(newPowerPoint.ActivePresentation.Slides.Count)



'复制图表并将其作为图元文件图片粘贴到PowerPoint中
cht.Select

ActiveChart.ChartArea.Copy

activeSlide.Shapes.PasteSpecial(DataType:= ppPasteMetafilePicture)。选择



'设置幻灯片的标题与图表的标题相同

activeSlide.Shapes(1).TextFrame.TextRange.Text = cht.Chart.ChartTitle.Text



'调整图表在Powerpoint幻灯片上的位置

newPowerPoint.ActiveWindow.Selection.ShapeRan ge.Left = 15

newPowerPoint.ActiveWindow.Selection.ShapeRange.Top = 125



activeSlide.Shapes(2).Width = 200

activeSlide.Shapes(2).Left = 505



下一页



AppActivate("Microsoft PowerPoint")

设置activeSlide = Nothing

设置newPowerPoint = Nothing



结束Sub

i am creating a Power point presentation having graphs which is having database in excel sheets.
i inserted codes in VBA but whenever i run the code ...every time new slides appear with changes , but i want to automate my existing slides , like as any change occur in excel , ppt should b automatically refreshed.here is the coding done in VBA..



Sub CreatePowerPoint()

'Add a reference to the Microsoft PowerPoint Library by:
'1. Go to Tools in the VBA menu
'2. Click on Reference
'3. Scroll down to Microsoft PowerPoint X.0 Object Library, check the box, and press Okay

'First we declare the variables we will be using
Dim newPowerPoint As PowerPoint.Application
Dim activeSlide As PowerPoint.Slide
Dim cht As Excel.ChartObject

'Look for existing instance
On Error Resume Next
Set newPowerPoint = GetObject(, "PowerPoint.Application")
On Error GoTo 0

'Let's create a new PowerPoint
If newPowerPoint Is Nothing Then
Set newPowerPoint = New PowerPoint.Application
End If
'Make a presentation in PowerPoint
If newPowerPoint.Presentations.Count = 0 Then
newPowerPoint.Presentations.Add
End If

'Show the PowerPoint
newPowerPoint.Visible = True

'Loop through each chart in the Excel worksheet and paste them into the PowerPoint
For Each cht In ActiveSheet.ChartObjects

'Add a new slide where we will paste the chart
newPowerPoint.ActivePresentation.Slides.Add newPowerPoint.ActivePresentation.Slides.Count + 1, ppLayoutText
newPowerPoint.ActiveWindow.View.GotoSlide newPowerPoint.ActivePresentation.Slides.Count
Set activeSlide = newPowerPoint.ActivePresentation.Slides(newPowerPoint.ActivePresentation.Slides.Count)

'Copy the chart and paste it into the PowerPoint as a Metafile Picture
cht.Select
ActiveChart.ChartArea.Copy
activeSlide.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture).Select

'Set the title of the slide the same as the title of the chart
activeSlide.Shapes(1).TextFrame.TextRange.Text = cht.Chart.ChartTitle.Text

'Adjust the positioning of the Chart on Powerpoint Slide
newPowerPoint.ActiveWindow.Selection.ShapeRange.Left = 15
newPowerPoint.ActiveWindow.Selection.ShapeRange.Top = 125

activeSlide.Shapes(2).Width = 200
activeSlide.Shapes(2).Left = 505

Next

AppActivate ("Microsoft PowerPoint")
Set activeSlide = Nothing
Set newPowerPoint = Nothing

End Sub

推荐答案

您好Rohit,

Hi Rohit,

此论坛适用于Visual Studio Net中的VB。 

This forum is for the VB in Visual Studio Net. 

对于VBA,你可以更好地试试这个论坛。

For VBA you can better try this forum.

http://social.msdn.microsoft.com/Forums/en-US/isvvba


这篇关于刷新powerpoint图表使用VB优秀数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆