ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

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

测试GrpChart.Application.DataSheet.Font没成功。

[复制链接]

TA的精华主题

TA的得分主题

发表于 2023-1-31 10:05 | 显示全部楼层 |阅读模式
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
本帖最后由 ning84 于 2023-1-31 19:42 编辑



dd.jpg

关键语句 GrpChart.Application.DataSheet.Font.Size,测试多次都没变化。








  1. Sub del11()
  2.    Dim Pres As Presentation
  3.    Dim Sld As Slide
  4.    Dim objChart As ChartObject
  5.    Dim oChart As Chart
  6.    Dim GrpChart As Graph.Chart
  7.    Dim GrpSht As Graph.DataSheet
  8.    Dim Shp As Shape
  9.    Dim ShpRng As ShapeRange
  10.       Set Pres = Application.ActivePresentation
  11.       Set Sld = Pres.Slides(1)
  12.       Set GrpChart = Sld.Shapes(1).OLEFormat.Object
  13.       GrpChart.Activate
  14.       
  15.       Set GrpSht = GrpChart.Application.DataSheet
  16.       GrpChart.HasDataTable = True
  17.       
  18.       With GrpChart.Application.DataSheet
  19.            .Activate
  20.            .Font.Size = 50
  21.            .Font.ColorIndex = 5
  22.       End With
  23.       ''
  24.       For ii = 1 To 1
  25.          'Debug.Print GrpChart.SeriesCollection(ii).Name
  26.           With GrpChart.SeriesCollection(ii)
  27.                 With .DataLabels
  28.                      .Font.Size = 15
  29.                      .HorizontalAlignment = xlRight
  30.                      .VerticalAlignment = xlTop
  31.                      .ReadingOrder = xlLTR
  32.                      .Position = xlLabelPositionInsideBase
  33.                      .Orientation = xlHorizonta
  34.                 End With
  35.          End With
  36.          
  37.       Next ii
  38.       'Set Shp = Sld.Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 10, 100, 20)
  39.       'Shp.TextFrame.TextRange.Text = "ffffffffffffffaaaaaa"
  40.       'Stop

  41. End Sub
复制代码
  1. Sub del()
  2.    Dim Pres As Presentation
  3.    Dim Sld As Slide
  4.    Dim Shp As Shape
  5.    Dim GrpChart As Graph.Chart
  6.        Set Pres = Application.ActivePresentation
  7.        Set GrpChart = Pres.Slides(1).Shapes(1).OLEFormat.Object
  8.       
  9.        With GrpChart
  10.              For ii = 1 To 3
  11.                  .SeriesCollection(ii).ApplyDataLabels AutoText:=True, LegendKey:= _
  12.                             False, ShowSeriesName:=False, ShowCategoryName:=False, ShowValue:=True, _
  13.                             ShowPercentage:=False, ShowBubbleSize:=False
  14.                 With .SeriesCollection(ii)
  15.                      Debug.Print .ChartType
  16.                      With .Border
  17.                            .Weight = xlThick
  18.                            .LineStyle = xlAutomatic
  19.                      End With
  20.                 End With

  21.              Next ii
  22.        End With
  23.       
  24.       
  25. End Sub
复制代码


a.zip

26.91 KB, 下载次数: 5

TA的精华主题

TA的得分主题

发表于 2023-1-31 16:00 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-1-31 21:56 | 显示全部楼层
没任何办法,只能宏录制一点一点测试。


  1. ''
  2. Sub del11()
  3.    Dim Pres As Presentation
  4.    Dim Sld As Slide
  5.    Dim objChart As ChartObject
  6.    Dim oChart As Chart
  7.    Dim GrpChart As Graph.Chart
  8.    Dim GrpSht As Graph.DataSheet
  9.    Dim Shp As Shape
  10.    Dim ShpRng As ShapeRange
  11.       Set Pres = Application.ActivePresentation
  12.       Set Sld = Pres.Slides(1)
  13.       Set GrpChart = Sld.Shapes(1).OLEFormat.Object
  14.       GrpChart.Activate
  15.       Set Shp = Sld.Shapes(1)
  16.       Set GrpSht = GrpChart.Application.DataSheet
  17.       GrpChart.HasDataTable = True
  18.       ''
  19.       For ii = 1 To 1
  20.           'Debug.Print GrpChart.SeriesCollection(ii).Name
  21.           With Shp
  22.                .Width = 500
  23.                .Height = 350
  24.                .Top = 100
  25.                .Left = 10
  26.           End With
  27.           With GrpChart.SeriesCollection(ii)
  28.                 GrpChart.ChartArea.Font.Size = 10
  29.                 With .DataLabels.Font
  30.                      .Name = "黑体"
  31.                      .FontStyle = "黑体"
  32.                      .Size = 10
  33.                      .Strikethrough = False
  34.                      .Superscript = False
  35.                      .Subscript = False
  36.                      .OutlineFont = False
  37.                      .Shadow = True
  38.                      .Underline = xlUnderlineStyleNone
  39.                      .ColorIndex = 1 'xlAutomatic
  40.                      .Background = xlOpaque
  41.                 End With
  42.                 With .DataLabels
  43.                      .Shadow = True
  44.                      .Interior.ColorIndex = 28
  45.                      .Interior.PatternColorIndex = 1
  46.                      .Interior.Pattern = xlSolid
  47.                      .Border.ColorIndex = xlThin
  48.                      .Border.Weight = xlMedium
  49.                      .Border.LineStyle = xlContinuous
  50.                      .Border.ColorIndex = 1
  51.                      .Border.Weight = xlMedium
  52.                      .Border.LineStyle = xlContinuous
  53.                 End With
  54.          End With
  55.       Next ii
  56. End Sub
复制代码

TA的精华主题

TA的得分主题

发表于 2023-2-1 08:07 来自手机 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
ning84 发表于 2023-1-31 21:56
没任何办法,只能宏录制一点一点测试。

https://learn.microsoft.com/zh-cn/office/vba/api/powerpoint.shapes

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-2-1 09:48 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
本帖最后由 ning84 于 2023-2-1 12:00 编辑

谢谢提供链接。学习Ppt-VBA难点是思维转不过来。习惯绑定引用项,层级太多,晕晕乎乎。
Dim Txt As TextRange, TxtFrm As TextFrame, TxtEFormat As TextEffectFormat
左绕右绕层级这个知识点,快要人奔溃了。


  1. Sub del21()
  2.     Dim Ppt As PowerPoint.Application
  3.     Dim Pres As Presentation
  4.     Dim Sld As Slide
  5.     Dim Shp As Shape
  6.     Dim ShpRng As ShapeRange
  7.     Dim TxtShp As Shape
  8.     Dim TxtFrm As TextFrame
  9.     Dim TxtRng As TextRange
  10.     Dim TxtEFmat As TextEffectFormat
  11.     Dim TxtSty As TextStyle
  12.     Dim Win As Window
  13.     Dim SldRng As SlideRange
  14.         
  15.    
  16.     'Dim Txt As TextRange, TxtFrm As TextFrame, TxtEFormat As TextEffectFormat
  17.          
  18.          Set Ppt = New PowerPoint.Application
  19.          'Set Win = Ppt.ActiveWindow
  20.          Set Pres = Ppt.ActivePresentation
  21.          Set Sld = Pres.Slides(1)


  22.          For Each Shp In Sld.Shapes
  23.               If Shp.Type = msoTextBox Then
  24.                    Set TxtFrm = Shp.TextFrame
  25.                    If TxtFrm.HasText = True Then
  26.                        Debug.Print TxtFrm.TextRange.Text
  27.                    End If
  28.                    Stop
  29.                   
  30.               End If
  31.          Next Shp
复制代码

************************************
SlideRange 对象 (PowerPoint) | Microsoft Learn  https://learn.microsoft.com/zh-c ... werpoint.sliderange


ShapeRange集合对象--------------用普通思路不好理解。

ShapeRange代表图形区域,该区域是文档中的一组图形。图形区域可包含一个图形,也可包含文档中的所有图形。可以在图形区域中包含所需的任意图形(在文档中的所有图形中选取,或在所有选定的图形中选取)。例如,可以构造包含文档中前三个图形、所有选定图形或所有任意多边形的 ShapeRange 集合。
关于如何使用一个形状或同时使用多个形状的概述,请参阅使用形状(绘图对象)。


ShapeRange.TextFrame 属性 (Excel) | Microsoft Learn  https://learn.microsoft.com/zh-c ... haperange.textframe
TextFram只有在Ppt有,Excel-VBA没有。

TextEffectFormat 对象 (PowerPoint) | Microsoft Learn  https://learn.microsoft.com/zh-c ... nt.texteffectformat

搞不清TextEffectFormat到底效果.




TA的精华主题

TA的得分主题

 楼主| 发表于 2023-2-1 14:55 | 显示全部楼层
ShapeRange 对象 (PowerPoint) | Microsoft Learn  https://learn.microsoft.com/zh-cn/office/vba/api/powerpoint.shaperange


花了好长时间,也没有学会,ShapeRange怎么用。

dd.jpg


Set myDocument = ActivePresentation.Slides(1)myDocument.Shapes.Range(Array(1, 3)).Fill _    .Patterned msoPatternHorizontalBrick


  1. Sub ll()
  2.    Dim Ppt As PowerPoint.Application
  3.    Dim Pres As Presentation
  4.    Dim Sld As Slide
  5.    Dim Shp As Shape
  6.    Dim ShpRng As ShapeRange
  7.    Dim TxtRng As TextRange
  8.    Dim TxtFrm As TextFrame
  9.    Dim TxtEFrm As TextEffectFormat
  10.    Dim TxtSty As TextStyle
  11.         Set Ppt = New PowerPoint.Application
  12.         Set Pres = Ppt.ActivePresentation
  13.         Set Sld = Pres.Slides(1)
  14.         For Each Shp In Sld.Shapes
  15.              If Shp.Type = msoTextBox Then
  16.                    Set TxtFrm = Shp.TextFrame
  17.                    If TxtFrm.HasText = True Then
  18.                         Set TxtRng = TxtFrm.TextRange
  19.                         Debug.Print TxtRng.Text
  20.                         Shp.TextFrame.TextRange.Text = "层级太多太复杂"
  21.                         With Shp
  22.                             .Left = 100
  23.                             .Top = 350
  24.                             .Width = 300
  25.                             Debug.Print .Left, .Top
  26.                         End With
  27.                         ''
  28.                         With TxtFrm
  29.                             .Orientation = msoTextOrientationVerticalFarEast
  30.                             .Orientation = msoTextOrientationHorizontal
  31.                             .WordWrap = msoTrue
  32.                             With .TextRange
  33.                                  Debug.Print .Length, .BoundLeft, .BoundWidth
  34.                                  Debug.Print .Font.Shadow
  35.                                  .Font.Shadow = msoFalse
  36.                                  .Font.Size = 30
  37.                             End With
  38.                         End With
  39.                         TxtFrm.TextRange.Font.Color.RGB = RGB(255, 255, 255)
  40.                         'Set ShpRng = Sld.Shapes(1).Range(1)
  41.                         Debug.Print Sld.Shapes.Range
  42.                         Sld.Shapes.Range(Array(1, 3)).Fill.Patterned msoPatternHorizontalBrick
  43.                         Stop
  44.                         ''
  45.                    End If
  46.              End If
  47.         Next Shp
  48. End Sub
  49. Sub Macro1()
  50. '
  51. ' 宏由 win 记录,日期: 2023/2/1
  52. '

  53.     ActiveWindow.Selection.SlideRange.Shapes("Text Box 39").Select
  54.     With ActiveWindow.Selection.ShapeRange
  55.         .IncrementLeft -0.88
  56.         .IncrementTop -0.62
  57.     End With
  58.     ActiveWindow.Selection.SlideRange.Shapes("Object 23").Select
  59.     ActiveWindow.Selection.SlideRange.Shapes("Text Box 39").Select
  60.     With ActiveWindow.Selection.ShapeRange
  61.         .Fill.Visible = msoTrue
  62.         .Fill.Solid
  63.         .Fill.ForeColor.RGB = RGB(153, 204, 255)
  64.         .Fill.Transparency = 0#
  65.         .Line.Visible = msoTrue
  66.         .Line.ForeColor.SchemeColor = ppForeground
  67.         .Line.BackColor.RGB = RGB(255, 255, 255)
  68.     End With
  69.     ActiveWindow.Selection.SlideRange.Shapes("Text Box 39").Select
  70.     ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Select
  71.     ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.Characters(Start:=1, Length:=8).Select
  72.     With ActiveWindow.Selection.TextRange.Font
  73.         .NameAscii = "Arial"
  74.         .NameOther = "Arial"
  75.         .NameFarEast = "华文行楷"
  76.         .Size = 30
  77.         .Bold = msoTrue
  78.         .Italic = msoFalse
  79.         .Underline = msoFalse
  80.         .Shadow = msoFalse
  81.         .Emboss = msoFalse
  82.         .BaselineOffset = 0
  83.         .AutoRotateNumbers = msoTrue
  84.         .Color.SchemeColor = ppForeground
  85.     End With
  86.     ActiveWindow.Selection.SlideRange.Shapes("Object 23").Select
  87.     ActiveWindow.Selection.SlideRange.Shapes("Text Box 39").Select
  88.     With ActiveWindow.Selection.ShapeRange
  89.         .Fill.Transparency = 0#
  90.         .Line.Weight = 1.5
  91.         .TextFrame.Orientation = msoTextOrientationVerticalFarEast
  92.     End With
  93.     ActiveWindow.Selection.Unselect
  94. End Sub
复制代码


TA的精华主题

TA的得分主题

发表于 2023-2-1 17:50 来自手机 | 显示全部楼层
本帖最后由 lss001 于 2023-2-2 10:44 编辑

ShapeRange 对象
一般操作选中的形状时使用, 表示选中的形状集合
Set SelShapeRng = ActiveWindows.Selection.ShapeRange '多个
Set SelShapeRng1 = ActiveWindows.Selection.ShapeRange(1) '单个
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

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

GMT+8, 2024-6-14 19:45 , Processed in 0.035229 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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