|
楼主 |
发表于 2023-1-21 12:12
|
显示全部楼层
本帖最后由 ning84 于 2023-1-22 13:51 编辑
使用VBA从Microsoft Excel将数据获取到Powerpoint图中 - 或代码 https://www.orcode.com/question/1475714_k406a2.html
再学习这个贴子,还是老问题类型定义。
- Sub L1()
- Dim Pres As Presentation
- Dim Sld As Slide
- Dim Shp As Shape
- Dim Grp As Graph.Chart
- Dim Obj 'As CellRange
- Dim Sht As Worksheet
- Dim ShpRng As ShapeRange
- Set Pres = Application.ActivePresentation
-
- For Each Sld In Pres.Slides
- Debug.Print Sld.Name
- For Each Shp In Sld.Shapes
- Set Grp = Shp.OLEFormat.Object
- Stop
- Debug.Print Shp.Name, DataSheetDataSheet; Shp.OLEFormat.Object.Application.Name
- With Grp
- Debug.Print .Name,
- 'Debug.Print .ChartTitle.Top,
- Debug.Print .ChartType
- 'Set Sht = Shp.OLEFormat.Object.Application.DataSheet
- End With
- Shp.Select msoCTrue
- Shp.OLEFormat.Object.Application.DataSheet.Cells(2, 2) = 2
- Set Obj = Shp.OLEFormat.Object.Application.DataSheet.Cells(2, 2) ' .Range("B2:W10")
- Debug.Print Obj.Value, ', Obj.Address
- Debug.Print Obj.Address
- Stop
- Stop
- Next Shp
- Next Sld
- End Sub
复制代码- Sub L1()
- Dim oPresent As Presentation
- Dim Sld As Slide
- Dim Shp As Shape
- ''
- Dim GrpChart As Graph.Chart
- Dim gSht As Graph.DataSheet
- Dim gRng As Graph.Range, gRng2 As Graph.Range
- ''
- Dim Obj 'As CellRange
- Dim Sht As Worksheet
- Dim ShpRng As ShapeRange
- Dim Path, xlPathName, xlName As String
-
- Dim xlWk As Excel.Workbook
- Dim Rng As Excel.Range, Rng1 As Excel.Range, Rng2 As Excel.Range
-
-
- xlName = "\del.xls"
- Set oPresent = Application.ActivePresentation
- Path = oPresent.Application.ActivePresentation.Path
-
- Set xlWk = PptSetWk("\中国东西南北城市.xls")
- For Each Sht In xlWk.Sheets
- 'Debug.Print Sht.Name
- Next Sht
- Set Sht = xlWk.Sheets("图表数据")
- With Sht
- Set Rng1 = .Range(.Cells(3, 1).Formula)
- Set Rng2 = .Range(.Cells(4, 1).Formula)
- Set Rng2 = Rng2(3, 1).Resize(1, Rng2.Columns.Count)
- 'Debug.Print Rng1.Address, Rng2.Address
- End With
-
- For Each Sld In oPresent.Slides
- For Each Shp In Sld.Shapes
- Set GrpChart = Shp.OLEFormat.Object
- 'Debug.Print Shp.Name, DataSheetDataSheet; Shp.OLEFormat.Object.Application.Name
- With GrpChart
- Debug.Print .Name, .Application.Name,
- Debug.Print .ChartType,
- Debug.Print .Left, .Top, .Width, .Height
- 'Stop
- End With
- Set gSht = Shp.OLEFormat.Object.Application.DataSheet
- With gSht
- .Cells(2, 1) = Format(Rng2(, 1), "mm月dd日") '"yy年mm月dd日")
- Stop
- For jj = 1 To Rng1.Columns.Count
- 'Debug.Print jj, .Cells(1, jj + 1).Value, Format(.Cells(2, jj + 1).Value, "h:mm")
- .Cells(1, jj + 1) = Rng1(, jj)
- .Cells(2, jj + 1) = Format(Rng2(, jj + 1), "h:mm")
- Next jj
-
- End With
- Next Shp
- Next Sld
- 'xlWk.Close
- 'xlWk.Parent.Application.Quit
- Debug.Print xlWk.Name
- xlWk.Application.Quit
- End Sub
复制代码
|
|