ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 413|回复: 7

[求助] 录制宏,没办法更改Microsoft Graph中的表格数据。

[复制链接]

TA的精华主题

TA的得分主题

发表于 2023-1-20 09:22 | 显示全部楼层 |阅读模式

PPT中插入Excel图表和Microsoft Graph的应用.-Excel图表与图形-ExcelHome技术论坛 -  https://club.excelhome.net/thread-534158-1-317.html?jdfwkey=btqng
Excel图表或Microsoft Graph  https://www.officeba.com.cn/arti ... 2008/5/29/2151.html

[分享]通过VBA在Word文档里添加Microsoft Graph图表的方法-Word-ExcelHome技术论坛 -  https://club.excelhome.net/forum ... amp;_dsign=5e141449

Microsoft Graph图表-ExcelHome  https://www.excelhome.net/1293.html


dd.jpg

录制的宏
  1.     ActiveSheet.Shapes("Object 1").Select
  2.     Selection.Verb Verb:=xlPrimary
  3.     Range("H17").Select
  4.     ActiveSheet.Shapes("Object 1").Select
  5.     Selection.Verb Verb:=xlPrimary
  6.     Range("H8").Select
复制代码


按录制宏编制程序,没办法更改Microsoft Graph中的数据。
  1. Sub dddd()
  2.    Dim Xl As Excel.Application
  3.        Set Xl = Excel.Application
  4.        Debug.Print Xl.Name
  5.    Dim xlWk As Workbook
  6.        Set xlWk = Xl.ActiveWorkbook
  7.        Debug.Print xlWk.Parent.Name
  8.    Dim Rng As Range, oRng As Range
  9.    Dim Rng1 As Range, Rng2 As Range
  10.        ''
  11.    Dim Shp As Shape
  12.    Dim Sht As Worksheet

  13.    For Each Sht In xlWk.Sheets
  14.       
  15.        For Each Shp In Sht.Shapes
  16.             Debug.Print Shp.Name, Shp.Application.Name,
  17.             Debug.Print Shp.OLEFormat.Object.Application.Name
  18.             ActiveSheet.Shapes(Shp.Name).Select
  19.    
  20.             Selection.Verb Verb:=xlPrimary
  21.             Set Rng = Range("H17").Select
  22.             Debug.Print Rng.Address, Rng.Parent.Name, Rng.Parent.Parent.Name
  23.        Next Shp
  24.    Next Sht
  25. End Sub
复制代码










a.zip

37.83 KB, 下载次数: 0

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-1-20 11:25 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
Microsoft Graph 概述 - Microsoft Graph | Microsoft Learn  https://learn.microsoft.com/zh-cn/graph/overview


就想更改Microsoft Graph的数据,怎么成为高难度的编程。

Microsoft Graph 概述
项目
2022/06/16
2 个参与者
Microsoft Graph 是 Microsoft 365 中通往数据和智能的网关。 它提供统一的可编程模型,可用于访问 Microsoft 365、Windows 10 和企业移动性 + 安全性中的海量数据。 利用 Microsoft Graph 中的大量数据针对与数百万名用户交互的组织和客户构建应用。

不想再深入学习,只想如何简单更改MicroSoft Graph的数据。
********************************************
dd1.jpg

dd2.jpg

寻求帮助,如何set ?? 剩下的就是excel的知识了。




TA的精华主题

TA的得分主题

 楼主| 发表于 2023-1-20 13:56 | 显示全部楼层
就想解决MicroSoft Graph的表格问题,怎么越学越深,有必要学习这么多知识吗?

Application 对象 (Excel Graph) | Microsoft Learn  https://learn.microsoft.com/zh-c ... cation-graph-object

*************************************
集合 提供有关此对象模型中集合的参考信息。

对象 提供有关此对象模型中对象的参考信息。

方法 提供有关此对象模型中方法的参考信息。

属性 提供有关此对象模型中属性的参考信息。

枚举 提供有关此对象模型中枚举的参考信息。

*************************************

选中活动单元格
以下示例代码通过将 ColorIndex 属性设为等于 0 来清除工作表上的所有单元格中的颜色,然后通过将 ColorIndex 属性设为等于 8(青绿色)来选中活动单元格。

VB

复制
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Application.ScreenUpdating = False
    ' Clear the color of all the cells
    Cells.Interior.ColorIndex = 0
    ' Highlight the active cell
    Target.Interior.ColorIndex = 8
    Application.ScreenUpdating = True
End Sub
选中包含活动单元格的整行和整列。
以下示例代码通过将 ColorIndex 属性设为等于 0 来清除工作表上的所有单元格中的颜色,然后通过使用 EntireRow 和 EntireColumn 属性选中包含活动单元格的整行和整列。

VB

复制
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
    Application.ScreenUpdating = False
    ' Clear the color of all the cells
    Cells.Interior.ColorIndex = 0
    With Target
        ' Highlight the entire row and column that contain the active cell
        .EntireRow.Interior.ColorIndex = 8
        .EntireColumn.Interior.ColorIndex = 8
    End With
    Application.ScreenUpdating = True
End Sub
选中当前区域内包含活动单元格的行和列
以下代码示例通过将 ColorIndex 属性设为等于 0 来清除工作表上的所有单元中的颜色,然后通过使用 Range 对象的 CurrentRegion 属性来选中当前区域内包含活动单元格的行和列。

VB

复制
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    ' Clear the color of all the cells
    Cells.Interior.ColorIndex = 0
    If IsEmpty(Target) Or Target.Cells.Count > 1 Then Exit Sub
    Application.ScreenUpdating = False
    With ActiveCell
        ' Highlight the row and column that contain the active cell, within the current region
        Range(Cells(.Row, .CurrentRegion.Column), Cells(.Row, .CurrentRegion.Columns.Count + .CurrentRegion.Column - 1)).Interior.ColorIndex = 8
        Range(Cells(.CurrentRegion.Row, .Column), Cells(.CurrentRegion.Rows.Count + .CurrentRegion.Row - 1, .Column)).Interior.ColorIndex = 8
    End With
    Application.ScreenUpdating = True
End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-1-21 07:48 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
使用VBA从Microsoft Excel将数据获取到Powerpoint图中 - 或代码  https://www.orcode.com/question/1475714_k406a2.html


dd.jpg
花时间测试这段程序,结果还是项目引用问题。思路稍微清晰一点。

  1. Sub l2()
  2. Dim myChart As Chart
  3.     Dim gChartData As ChartData
  4.     Dim gWorkBook As Excel.Workbook
  5.     Dim gWorkSheet As Excel.Worksheet

  6.    
  7.     Set myChart = ActivePresentation.Slides(1).Shapes.AddChart.Chart
  8.     Set gChartData = myChart.ChartData

  9.    
  10.     Set gWorkBook = gChartData.Workbook
  11.     Set gWorkSheet = gWorkBook.Worksheets(1)
  12. End Sub
复制代码

  1. Sub L1()
  2.     Dim Pres As Presentation
  3.     Dim Sld As Slide
  4.     Dim Shp As Shape
  5.     Dim a
  6.     Dim ShpRng As ShapeRange
  7.         Set Pres = Application.ActivePresentation
  8.         
  9.         For Each Sld In Pres.Slides
  10.               Debug.Print Sld.Name
  11.               For Each Shp In Sld.Shapes
  12.                     Debug.Print Shp.Name, DataSheetDataSheet; Shp.OLEFormat.Object.Application.Name
  13.                     Shp.Select msoCTrue
  14.                     Shp.OLEFormat.Object.Application.DataSheet.Cells(2, 2) = 2
  15.               Next Shp
  16.         Next Sld
  17. End Sub
复制代码


在网上找了很长时间,也没用找到Application.DataSheet.Cells的出处在什么地。

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-1-21 10:20 | 显示全部楼层
dd.jpg


Dim Obj应该如何定义????
Range不成立。


Sub L1()
    Dim Pres As Presentation
    Dim Sld As Slide
    Dim Shp As Shape
    Dim Obj 'As CellRange
   
    Dim ShpRng As ShapeRange
        Set Pres = Application.ActivePresentation
        
        For Each Sld In Pres.Slides
              Debug.Print Sld.Name
              For Each Shp In Sld.Shapes
                    Debug.Print Shp.Name, DataSheetDataSheet; Shp.OLEFormat.Object.Application.Name
                    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")
                    Stop
              Next Shp
        Next Sld
End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-1-21 12:12 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
本帖最后由 ning84 于 2023-1-22 13:51 编辑

使用VBA从Microsoft Excel将数据获取到Powerpoint图中 - 或代码  https://www.orcode.com/question/1475714_k406a2.html

再学习这个贴子,还是老问题类型定义。

dd1.jpg dd2.jpg


  1. Sub L1()
  2.     Dim Pres As Presentation
  3.     Dim Sld As Slide
  4.     Dim Shp As Shape
  5.     Dim Grp As Graph.Chart
  6.     Dim Obj 'As CellRange
  7.     Dim Sht As Worksheet
  8.     Dim ShpRng As ShapeRange
  9.         Set Pres = Application.ActivePresentation
  10.         
  11.         For Each Sld In Pres.Slides
  12.               Debug.Print Sld.Name
  13.               For Each Shp In Sld.Shapes
  14.                     Set Grp = Shp.OLEFormat.Object
  15.                     Stop
  16.                     Debug.Print Shp.Name, DataSheetDataSheet; Shp.OLEFormat.Object.Application.Name
  17.                     With Grp
  18.                          Debug.Print .Name,
  19.                          'Debug.Print .ChartTitle.Top,
  20.                          Debug.Print .ChartType
  21.                          'Set Sht = Shp.OLEFormat.Object.Application.DataSheet
  22.                     End With
  23.                     Shp.Select msoCTrue
  24.                     Shp.OLEFormat.Object.Application.DataSheet.Cells(2, 2) = 2
  25.                     Set Obj = Shp.OLEFormat.Object.Application.DataSheet.Cells(2, 2) ' .Range("B2:W10")
  26.                     Debug.Print Obj.Value, ', Obj.Address
  27.                     Debug.Print Obj.Address
  28.                     Stop
  29.                     Stop
  30.               Next Shp
  31.         Next Sld
  32. End Sub
复制代码
  1. Sub L1()

  2.     Dim oPresent As Presentation
  3.     Dim Sld As Slide
  4.     Dim Shp As Shape
  5.     ''
  6.     Dim GrpChart As Graph.Chart
  7.     Dim gSht As Graph.DataSheet
  8.     Dim gRng As Graph.Range, gRng2 As Graph.Range
  9.     ''
  10.     Dim Obj 'As CellRange
  11.     Dim Sht As Worksheet
  12.     Dim ShpRng As ShapeRange
  13.     Dim Path, xlPathName, xlName As String
  14.    
  15.     Dim xlWk As Excel.Workbook
  16.     Dim Rng As Excel.Range, Rng1 As Excel.Range, Rng2 As Excel.Range
  17.    
  18.    
  19.         xlName = "\del.xls"
  20.         Set oPresent = Application.ActivePresentation
  21.         Path = oPresent.Application.ActivePresentation.Path
  22.         
  23.         Set xlWk = PptSetWk("\中国东西南北城市.xls")
  24.   For Each Sht In xlWk.Sheets
  25.        'Debug.Print Sht.Name
  26.   Next Sht
  27.         Set Sht = xlWk.Sheets("图表数据")
  28.         With Sht
  29.             Set Rng1 = .Range(.Cells(3, 1).Formula)
  30.             Set Rng2 = .Range(.Cells(4, 1).Formula)
  31.             Set Rng2 = Rng2(3, 1).Resize(1, Rng2.Columns.Count)
  32.             'Debug.Print Rng1.Address, Rng2.Address
  33.         End With
  34.         


  35.         For Each Sld In oPresent.Slides
  36.               For Each Shp In Sld.Shapes
  37.                     Set GrpChart = Shp.OLEFormat.Object
  38.                     'Debug.Print Shp.Name, DataSheetDataSheet; Shp.OLEFormat.Object.Application.Name
  39.                     With GrpChart
  40.                          Debug.Print .Name, .Application.Name,
  41.                          Debug.Print .ChartType,
  42.                          Debug.Print .Left, .Top, .Width, .Height
  43.                          'Stop
  44.                     End With
  45.                     Set gSht = Shp.OLEFormat.Object.Application.DataSheet
  46.                     With gSht
  47.                           .Cells(2, 1) = Format(Rng2(, 1), "mm月dd日") '"yy年mm月dd日")
  48.                           Stop
  49.                           For jj = 1 To Rng1.Columns.Count
  50.                                 'Debug.Print jj, .Cells(1, jj + 1).Value, Format(.Cells(2, jj + 1).Value, "h:mm")
  51.                                 .Cells(1, jj + 1) = Rng1(, jj)
  52.                                 .Cells(2, jj + 1) = Format(Rng2(, jj + 1), "h:mm")
  53.                           Next jj
  54.                           
  55.                     End With
  56.               Next Shp
  57.         Next Sld
  58.         'xlWk.Close
  59.         'xlWk.Parent.Application.Quit
  60.         Debug.Print xlWk.Name
  61.         xlWk.Application.Quit
  62. End Sub
复制代码

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-1-25 07:09 | 显示全部楼层
  1. Sub dadada()
  2.    Dim Ppt As PowerPoint.Application
  3.    Dim Pres As PowerPoint.Presentation
  4.    Dim GrpChart As Graph.Chart
  5.    Dim Sld As Slide
  6.    Dim S As Object
  7.    Dim Shp As Shape
  8.        Set Ppt = New PowerPoint.Application
  9.        Set Pres = Ppt.ActivePresentation
  10.        For Each Sld In Pres.Slides
  11.              For Each S In Sld.Shapes
  12.                   Debug.Print S.Type, S.OLEFormat.Object.Type
  13.                   Set GrpChart = S.OLEFormat.Object
  14.                   Debug.Print GrpChart.Name, GrpChart.ChartType
  15.              Next S
  16.              For ii = 1 To Sld.Shapes.Count
  17.                   Debug.Print Sld.Shapes(ii).Type
  18.              Next ii
  19.              For Each Shp In Sld.Shapes
  20.                   Debug.Print Shp.Name, Shp.OLEFormat.Object.Type
  21.              Next Shp
  22.        Next Sld
  23.       
  24. End Sub
复制代码


dd.jpg

ppt环境Shape成立,excel环境Shape不成立。



  1. Sub dddd()
  2.    
  3.    Dim GrpChart  As Graph.Chart
  4.    Dim GrpSht As Graph.DataSheet
  5.    Dim S As Object
  6.    Dim Shp As Shape
  7.    Dim Sld As Slide
  8.    Dim Pres As Presentation
  9.    Dim Ppt As PowerPoint.Application
  10.    Dim Sht As Worksheet
  11.        Set Sht = ThisWorkbook.ActiveSheet
  12.        Set Ppt = New PowerPoint.Application
  13.       
  14.        'Set Pres = OpenPpt("D:\日出日落\a.ppt")
  15.        Set Pres = Ppt.ActivePresentation
  16.        Debug.Print Pres.FullName

  17.       
  18.        For Each Sld In Pres.Slides
  19.             
  20.             For Each S In Sld.Shapes
  21.                  If S.Type = 7 Then
  22.                        Set GrpChart = S.OLEFormat.Object
  23.                        ''
  24.                        With GrpChart
  25.                                   .ChartType = xlLineMarkersStacked
  26.                                   .HasTitle = False
  27.                                   .HasLegend = False
  28.                                   .HasDataTable = True
  29.                                   For iiii = 1 To 3
  30.                                         With .SeriesCollection(iiii).Border
  31.                                              .Weight = xlThick
  32.                                              '.ColorIndex = Rnd(10)
  33.                                              Debug.Print .ColorIndex
  34.                                              .LineStyle = xlContinuous
  35.                                         End With
  36.                                   Next iiii
  37.                       End With
  38.                   End If
  39.             Next S
  40.        Next Sld
  41. End Sub
复制代码




a.zip

24.52 KB, 下载次数: 0

TA的精华主题

TA的得分主题

发表于 2023-1-28 00:42 来自手机 | 显示全部楼层
本帖最后由 lss001 于 2023-2-6 15:06 编辑

Sub ExcelMSGraphChart8修改图表数据()
    Set Myole = ActiveSheet.Shapes("Object 1")
    Myole.Select '选中对象
    Set Mycha = Myole.OLEFormat.Object.Object
    Mycha.Application.DataSheet.Cells(2, 2) = 10
End Sub
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-6-10 04:11 , Processed in 1.055198 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表