|
匆忙之中,先试一试。
所需演示文稿.zip
(48.13 KB, 下载次数: 288)
Dim Myarr()
Sub MylineExcel()
Dim Mypath As String, Myfile As String
Dim Myshe As Object, Myole As Object, Mycha As Object
Dim bta As Integer, btc As Integer, btk As Integer
Dim btb(), hdsz()
Mypath = ActivePresentation.Path '获得工作路径
Myfile = Dir(Mypath & "\数据源.xls") '返回一个Excel文件名
If Myfile = "" Then Exit Sub
Set Myshe = GetObject(Mypath & "\数据源.xls").worksheets("sheet1")
Myarr = Myshe.UsedRange.Value '数组赋值
Set Myshe = Nothing '清空对象
a = 0
bta = 1
btc = UBound(Myarr, 1)
btk = UBound(Myarr, 2)
ReDim Preserve btb(0)
btb(0) = 1
For i = 1 To btc '该循环为取得"小计"的行
If Myarr(i, 1) Like "*小计*" Then
a = a + 1
ReDim Preserve btb(a)
btb(a) = i
End If
Next i
For i = ActivePresentation.Slides.Count To 1 Step -1 '该循环删除所有幻灯片
ActivePresentation.Slides(i).Delete
Next i
For i = 1 To UBound(btb)
For k = 2 To UBound(Myarr, 2)
Set mynewslide = ActivePresentation.Slides.Add(Index:=ActivePresentation.Slides.Count + 1, Layout:=ppLayoutBlank) '添加幻灯片
Set Myole = mynewslide.Shapes.AddOLEObject _
(Left:=10, Top:=10, Width:=700, Height:=500, ClassName:="MSGraph.Chart", Link:=msoTrue) '添加嵌入图表,设置对象
Myole.Name = "Mychart" & 1 '设置图表名称
Set Mycha = Myole.OLEFormat.Object '设置对象
Mycha.ChartType = 65 '图表类型为_数据点折线图
Mycha.Application.PlotBy = 2 '图表产生在列上
Mycha.Parent.datasheet.Cells.Clear '清除图表数据表中所有数据
hdsz = scsz(btb(i - 1), btb(i), k) '取得所需的数据数组
For ro = 1 To UBound(hdsz, 1) '该循环给图表数据表加入数据
For co = 1 To UBound(hdsz, 2)
Mycha.Parent.datasheet.Cells(ro, co) = hdsz(ro, co) '给图表数据表加入数据
Next co
Next ro
Next k
Next i
End Sub
Function scsz(ByVal fw1 As Integer, ByVal fw2 As Integer, ByVal b1 As Integer) '取得所需的数据数组
Dim t1 As Integer
Dim sjsz()
ReDim sjsz(1 To fw2 - fw1, 1 To 4)
sjsz(1, 1) = ""
sjsz(1, 2) = Myarr(1, b1)
sjsz(1, 3) = Myarr(fw2, 1)
sjsz(1, 4) = Myarr(UBound(Myarr, 1), 1)
t1 = 2
For i = fw1 + 1 To fw2 - 1
sjsz(t1, 1) = Myarr(i, 1)
sjsz(t1, 2) = Myarr(i, b1)
sjsz(t1, 3) = Myarr(fw2, b1)
sjsz(t1, 4) = Myarr(UBound(Myarr, 1), b1)
t1 = t1 + 1
Next i
scsz = sjsz
End Function |
|