ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

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

[求助] 如何获取ApplyDataLabels各命名参数的值?

[复制链接]

TA的精华主题

TA的得分主题

发表于 2012-5-26 17:14 | 显示全部楼层 |阅读模式
例如,一个柱形图显示出数值,使用宏录制的VBA语句是:ActiveChart.ApplyDataLabels AutoText:=True, ShowValue:=True,......
可是如果我想使用VBA语句来判断一个柱形图是否显示出了数值,使用 If ActiveChart.ApplyDataLabels AutoText:=True  Then  msgbox()
却是出错的。该如何使用VBA语句来判断柱形图是否显示出了数值?或者说该如何获取ApplyDataLabels各命名参数的值?
请高手赐教为盼。

TA的精华主题

TA的得分主题

发表于 2012-5-27 12:29 | 显示全部楼层
If ActiveChart.SeriesCollection(1).HasDataLabels = True Then MsgBox "ssss"

TA的精华主题

TA的得分主题

发表于 2023-1-30 17:33 | 显示全部楼层
ChartSheet.SeriesCollection(Object) 方法 (Microsoft.Office.Tools.Excel) | Microsoft Learn  https://learn.microsoft.com/zh-c ... tion_System_Object_

DataLabels 方法 (Excel Graph) | Microsoft Learn  https://learn.microsoft.com/zh-t ... labels-graph-method
.SeriesCollection(2).DataLabels给颜色赋值要几级?-Excel VBA程序开发-ExcelHome技术论坛 -  https://club.excelhome.net/thread-1635098-1-1.html

下面程序卡在这里
人工选择可行,在程序里出问题了。
    With Selection
        .ReadingOrder = xlLTR
        .Position = xlLabelPositionInsideBase 'xlLabelPositionInsideEnd
        .Orientation = xlHorizontal
    End With

  1. Sub nnnn()
  2.     Dim objChart As ChartObject
  3.     Dim oChart As Chart
  4.     Dim Shp As Shape
  5.     Dim p As Point
  6.     Set objChart = Sheet1.ChartObjects(1)
  7.     objChart.Select
  8.     Debug.Print objChart.Name
  9.     Set oChart = objChart.Chart
  10.     'Active.Sheet.ChartObjects(oChart.Name).Activate
  11.   Application.ScreenUpdating = False
  12.   xVals = ActiveChart.SeriesCollection(1).Formula
  13.   'ActiveChart.Activate
  14.   'oChart.ChartArea.Select
  15.   'ActiveChart.SeriesCollection(1).DataLabels.Select
  16.     With oChart
  17.         xx = .SeriesCollection(1).Formula
  18.         Debug.Print xx
  19.         '.DataTable.ShowLegendKey = False
  20.         .SeriesCollection(1).ApplyDataLabels AutoText:=True, LegendKey:= _
  21.             False, ShowSeriesName:=False, ShowCategoryName:=True, ShowValue:=True, _
  22.             ShowPercentage:=False, ShowBubbleSize:=False

  23.         Set p = .SeriesCollection(1).Points(5)
  24.         p.Interior.ColorIndex = 3
  25.         
  26.         Stop
  27.         
  28.     .SeriesCollection(1).DataLabels.Select
  29.    
  30.         '.HorizontalAlignment = xlLeft
  31.         '.VerticalAlignment = xlTop
  32.     With Selection
  33.         .ReadingOrder = xlLTR
  34.         .Position = xlLabelPositionInsideBase 'xlLabelPositionInsideEnd
  35.         .Orientation = xlHorizontal
  36.     End With
  37.     End With
  38.    
  39. End Sub
复制代码

TA的精华主题

TA的得分主题

发表于 2023-1-30 19:22 | 显示全部楼层
钻到死胡同里,怎么也出不来。程序过不去的点是objChart.Activate
  1. Sub del11()
  2.    Dim objChart As ChartObject
  3.    Dim oChart As Chart
  4.       Set objChart = Sheet1.ChartObjects(1)
  5.       
  6.       
  7.       objChart.Activate
  8.       Set oChart = objChart.Chart
  9.       ''
  10.       With oChart.SeriesCollection(1).DataLabels
  11.            .HorizontalAlignment = xlRight
  12.            .VerticalAlignment = xlTop
  13.            .ReadingOrder = xlLTR
  14.            .Position = xlLabelPositionInsideBase
  15.            .Orientation = xlHorizontal
  16.       End With
  17. End Sub
复制代码

TA的精华主题

TA的得分主题

发表于 2023-1-30 21:11 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
ning84 发表于 2023-1-30 17:33
ChartSheet.SeriesCollection(Object) 方法 (Microsoft.Office.Tools.Excel) | Microsoft Learn  https://l ...

文件传上来看看

TA的精华主题

TA的得分主题

发表于 2023-1-30 22:12 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
  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 Shp As Shape
  8.    Dim ShpRng As ShapeRange
  9.       Set Pres = Application.ActivePresentation
  10.       Set Sld = Pres.Slides(1)
  11.       Set GrpChart = Sld.Shapes(1).OLEFormat.Object
  12.       GrpChart.Activate
  13.       
  14.       ''
  15.       For ii = 1 To 1
  16.          'Debug.Print GrpChart.SeriesCollection(ii).Name
  17.           With GrpChart.SeriesCollection(ii)
  18.                 With .DataLabels
  19.                      .Font.Size = 15
  20.                      .HorizontalAlignment = xlRight
  21.                      .VerticalAlignment = xlTop
  22.                      .ReadingOrder = xlLTR
  23.                      .Position = xlLabelPositionInsideBase
  24.                      .Orientation = xlHorizonta
  25.                      
  26.                 End With
  27.                
  28.          End With
  29.       Next ii
  30.       Set Shp = Sld.Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 10, 100, 20)
  31.       Shp.TextFrame.TextRange.Text = "ffffffffffffffaaaaaa"
  32.       Stop

  33. End Sub
复制代码
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

关闭

最新热点上一条 /1 下一条

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

GMT+8, 2024-6-1 21:11 , Processed in 0.037663 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

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

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

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