如何“刷新数据”通过Power Point的VBA? [英] How to "Refresh Data" via VBA in Power Point?

查看:311
本文介绍了如何“刷新数据”通过Power Point的VBA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我已经尝试了 Chart.Refresh Chart.Update ,还尝试了 ChartData.UpdateLinks ,两者都不起作用。
我的问题类似于这一个,只是这段代码不适用于我的ppt
如何在powerpoint中更新excel嵌入式图表?



如果我可以像Excel一样记录宏,步骤将是:



1.选择图表



2.Chart工具> 刷新数据 p>

这是代码是我设法写的,但是在gChart.Application.RefreshData中失败:

  Sub refreshchart()
Dim ppApp As PowerPoint.Application,sld As Slide
Dim s As PowerPoint.Shape
Dim gChart As Chart,i As Integer
ppApp.Visible = True
i = 3
Set sld = ActivePresentation.Slides(i)
sld.Select
对于每个s在ActivePresentation.Slides(i)
如果s.Type = msoEmbeddedOLEObject然后
设置gChart = s.OLEFormat.Object
使用gChart.Application

gChart.Application.Refresh
设置gChart = Nothing
结束如果
下一步s

End Sub

整数我被包括从i = 1到73,但作为测试我使用幻灯片3.不是所有的幻灯片都有图表大部分都有4张图表(73张中的65张)。



非常感谢您的帮助! =)

解决方案




编辑
下面的代码在Excel工作簿中的宏中,该工作簿还包含源数据。不知道代码是否是从PowerPoint运行的代码。我只是打开我的Excel工作簿,然后让它更新PowerPoint为我。






我一直在寻找永远找到回答这个问题,最后设法让它处理大量的阅读和试​​错。我的问题是,我有一个PowerPoint与许多图形创建与CTRL + C和CTRL + V,所以没有一个链接。
这是我如何工作:

  Dim myPresentation As PowerPoint.Presentation 
Dim sld As PowerPoint.Slide
Dim shp As PowerPoint.Shape
Dim myChart As PowerPoint.Chart

对于每个sld在myPresentation.Slides
对于每个shp在sld.Shapes
如果shp.HasChart然后
设置myChart = shp.Chart
myChart.ChartData.Activate
myChart.Refresh
结束如果
下一个
下一个

我不知道那里是否有不必要的代码,但我很高兴我终于得到了它工作,所以我不会感动它了。希望这可以帮助你。


so far I have tried the Chart.Refresh and Chart.Update and also ChartData.UpdateLinks and neither work. My question is similar to this one only that this code did not work for my ppt How to update excel embedded charts in powerpoint?

If i could Record Macro like in Excel the steps would be:

1.Select Chart

2.Chart Tools > Refresh Data

This is code is what I have managed to write but it fails at "gChart.Application.RefreshData":

Sub refreshchart()
    Dim ppApp As PowerPoint.Application, sld As Slide
    Dim s As PowerPoint.Shape
    Dim gChart As Chart, i As Integer
    ppApp.Visible = True
    i = 3
     Set sld = ActivePresentation.Slides(i)
    sld.Select
   For Each s In ActivePresentation.Slides(i)
    If s.Type = msoEmbeddedOLEObject Then
   Set gChart = s.OLEFormat.Object
   With gChart.Application

   gChart.Application.Refresh
   Set gChart = Nothing
   End If
  Next s

 End Sub

The Integer i is included to go from i=1 To 73, but as a test i am using Slide 3. Not all Slides have Charts but most of them have 4 Charts (65 out of 73).

Thank you so very much for your help!! =)

解决方案


edit The code below is in a macro in the Excel workbook which also contains the source data. Not sure if the code would be the same running it from PowerPoint. I simply open my Excel Workbook and then have it update the PowerPoint for me.


I have been looking forever to find an answer to this and finally managed to get it to work with a ton of reading and trial-and-error. My problem was that I have a PowerPoint with a lot of graphs that were created with CTRL+C and CTRL+V, so none of them are linked. This is how I got it to work:

Dim myPresentation As PowerPoint.Presentation
Dim sld As PowerPoint.Slide
Dim shp As PowerPoint.Shape
Dim myChart As PowerPoint.Chart

For Each sld In myPresentation.Slides
    For Each shp In sld.Shapes
        If shp.HasChart Then
            Set myChart = shp.Chart
            myChart.ChartData.Activate
            myChart.Refresh
        End If
    Next
Next

I don't know if there is unnecessary code in there but I am just happy that I finally got it to work so I'm not touching it anymore. Hope this helps you.

这篇关于如何“刷新数据”通过Power Point的VBA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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