Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 10504|回复: 13

[已解决]如何用VBA调整图表里折线的颜色和平滑型

[复制链接]
发表于 2012-11-26 20:06 | 显示全部楼层 |阅读模式
QQ截图20121126200309.png 大家好!前天论坛的高手帮了录了个宏设置折线的粗细的,可是到我这里录其他属性的设置时宏又不行了。
请帮忙录个宏,我想看看在宏里面图表里折线的颜色和平滑型,以及变为虚线,是如何应用的,因为我本人录完后,上面和下面的代码都是,搞不懂为什么?另外,可否帮忙说下这样的宏要怎么才能录?
ActiveSheet.ChartObjects("图表 20").Activate
ActiveSheet.ChartObjects("图表 20").Activate

最佳答案
2012-11-26 20:58
  1. Sub 宏1()
  2. '
  3. ' 宏1 宏
  4. '

  5. '
  6.    
  7.     'ActiveSheet.ChartObjects("2030").Activate
  8.     ActiveChart.SeriesCollection(1).Smooth = True
  9.     With Selection.Format.Line
  10.         .ForeColor.ObjectThemeColor = msoThemeColorAccent1
  11.         .ForeColor.TintAndShade = 0
  12.         .ForeColor.Brightness = 0
  13.     End With
  14.     With Selection.Format.Line
  15.         .Visible = msoTrue
  16.         .ForeColor.RGB = RGB(255, 0, 0)
  17.         .Transparency = 0
  18.     End With
  19.     With Selection.Format.Line
  20.         .DashStyle = msoLineSysDash
  21.     End With
  22. End Sub
复制代码
上面的颜色有问题,改了下。

111.zip

15.75 KB, 下载次数: 26

发表于 2012-11-26 20:48 | 显示全部楼层
回复

使用道具 举报

 楼主| 发表于 2012-11-26 20:54 | 显示全部楼层
hwc2ycy 发表于 2012-11-26 20:48
偶来了,楼主。

哎呀,您可来了,我这都琢磨2天了,行行好,帮帮忙吧!我想知道您是怎么录的,为什么我就录不出来了?万分感谢啊!
回复

使用道具 举报

发表于 2012-11-26 20:56 | 显示全部楼层
  1. Sub 宏1()
  2. '
  3. ' 宏1 宏
  4. '

  5. '
  6.    
  7.     'ActiveSheet.ChartObjects("2030").Activate
  8.     ActiveChart.SeriesCollection(1).Smooth = True
  9.     With Selection.Format.Line
  10.         .ForeColor.ObjectThemeColor = msoThemeColorAccent1
  11.         .ForeColor.TintAndShade = 0
  12.         '.ForeColor.Brightness = 0
  13.     End With
  14.     With Selection.Format.Line
  15.         '.Visible = msoTrue
  16.         .ForeColor.RGB = RGB(255, 0, 0)
  17.     End With
  18.     With Selection.Format.Line
  19.         .DashStyle = msoLineSysDash
  20.     End With
  21. End Sub
复制代码
回复

使用道具 举报

发表于 2012-11-26 20:58 | 显示全部楼层    本楼为最佳答案   
  1. Sub 宏1()
  2. '
  3. ' 宏1 宏
  4. '

  5. '
  6.    
  7.     'ActiveSheet.ChartObjects("2030").Activate
  8.     ActiveChart.SeriesCollection(1).Smooth = True
  9.     With Selection.Format.Line
  10.         .ForeColor.ObjectThemeColor = msoThemeColorAccent1
  11.         .ForeColor.TintAndShade = 0
  12.         .ForeColor.Brightness = 0
  13.     End With
  14.     With Selection.Format.Line
  15.         .Visible = msoTrue
  16.         .ForeColor.RGB = RGB(255, 0, 0)
  17.         .Transparency = 0
  18.     End With
  19.     With Selection.Format.Line
  20.         .DashStyle = msoLineSysDash
  21.     End With
  22. End Sub
复制代码
上面的颜色有问题,改了下。
回复

使用道具 举报

发表于 2012-11-26 20:59 | 显示全部楼层
录宏是一样的,你只改你需要的。然后比对。
实在不行,还可以查帮助呀。
回复

使用道具 举报

发表于 2012-11-26 21:07 | 显示全部楼层
  1. Sub 宏1()
  2.     'ActiveSheet.ChartObjects("2030").Activate
  3.     'ActiveSheet.ChartObjects("2030").Activate

  4.     ActiveChart.SeriesCollection(1).Select
  5.         ActiveChart.SeriesCollection(1).Smooth = True
  6.     With Selection.Format.Line
  7.         .ForeColor.ObjectThemeColor = msoThemeColorAccent1
  8.         .ForeColor.TintAndShade = 0
  9.         .ForeColor.Brightness = 0
  10.     End With
  11.     With Selection.Format.Line
  12.         .Visible = msoTrue
  13.         .ForeColor.RGB = RGB(255, 0, 0)
  14.         .Transparency = 0
  15.     End With
  16.     With Selection.Format.Line
  17.         .DashStyle = msoLineSysDash
  18.     End With
  19. End Sub
复制代码
回复

使用道具 举报

发表于 2012-11-26 21:21 | 显示全部楼层
  1. Sub 宏1()
  2.    
  3.     ActiveSheet.ChartObjects(1).Activate
  4.     ActiveChart.SeriesCollection(1).Select
  5.         ActiveChart.SeriesCollection(1).Smooth = True
  6.     With Selection.Format.Line
  7.         .ForeColor.ObjectThemeColor = msoThemeColorAccent1
  8.         .ForeColor.TintAndShade = 0
  9.         .ForeColor.Brightness = 0
  10.     End With
  11.     With Selection.Format.Line
  12.         .Visible = msoTrue
  13.         .ForeColor.RGB = RGB(255, 0, 0)
  14.         .Transparency = 0
  15.     End With
  16.     With Selection.Format.Line
  17.         .DashStyle = msoLineSysDash
  18.     End With
  19. End Sub
复制代码
奇怪,不能用图形的名字直接访问。
回复

使用道具 举报

发表于 2012-11-26 21:34 | 显示全部楼层
ActiveSheet.Shapes("2030").Select
用名字访问的方法,原来得这样。
回复

使用道具 举报

 楼主| 发表于 2012-11-26 22:15 | 显示全部楼层
hwc2ycy 发表于 2012-11-26 21:34
ActiveSheet.Shapes("2030").Select
用名字访问的方法,原来得这样。

您真是一大好人啊,我先研究去,非常感谢!可是录制宏的方法我觉得和别人没啥区别啊,点击开始,然后操作,改变折线的粗细,线体的颜色,改为虚线,所有的操作都完了,然后点击宏结束按钮,可进去一看,除了选择chartobject为活动对象外,中间没啥代码?百思不得其解,可否将您的操作弄成GIF图片给我参考参考啊!再次非常感谢!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-3-29 18:54 , Processed in 0.498657 second(s), 13 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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