VBA从excel中获取数据 [英] VBA gettng data from excel

查看:75
本文介绍了VBA从excel中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个带有通过 Excel 生成的图表的幻灯片.

I currently have a powerpoint with a chart that was generated through an excel.

我需要做的是获取图表(或 excel,无所谓)的值,以便制作一些动画.

What I need to do is get the values of the chart (or the excel, doesn't matter) in order to do some animations.

问题是我似乎无法让我的代码工作.

The problem is that I can't seem to get my code to work.

如果有任何更简单的方法可以做到这一点,我会很高兴听到的!

If there is ANY easier way to do this I will be glad to hear it!

这是我的代码:

Sub moveRectangle()
Dim pptChart As Chart
Dim pptcd As ChartData
Dim xlWorkbook As Object
Dim PPPres As Presentation
Dim pptShape2 As Shape
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
Dim sld As Slide
Dim shp As Shape
Dim PPApp As PowerPoint.Application
 'Look for existing instance
On Error Resume Next
Set PPApp = GetObject(, "PowerPoint.Application")
On Error GoTo 0
 'Create new instance if no instance exists
Set PPApp = CreateObject("Powerpoint.Application")
Set PPPres = PPApp.ActivePresentation
Set pptShape = PPPres.Slides(1).Shapes("Rectangle 16")
Set pptShape2 = PPPres.Slides(1).Shapes("Chart 3")
Set pptChart = pptShape2.Chart
Set pptcd = pptChart.ChartData
MsgBox (pptShape2.Name)
Set wb = pptcd.Workbook
Set ws = wb.Worksheets(1)
pptShape.Left = pptShape.Left - 40
End Sub

问题是我收到以下错误:

The problem is that I'm getting the following error:

Method 'Workbook' of Object 'ChartData' failed

非常感谢任何帮助!

推荐答案

为了让它在不激活"excel(存在全屏模式,很烦人)的情况下工作,必须做的是添加

In order to get it working without "activating" excel (which exists full screen mode, pretty annoying), what must be done is adding

With pptChart.ChartData
...
End With

这使您无需激活excel"即可获得相同的功能

This allows you to get the same functionalities without having to "activate excel"

这篇关于VBA从excel中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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