打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
线表计划高级阶段-随心所欲画图形


 前言

前边两章学了直线的画法,那么其他的图形如何画呢?其实非诚简单,既然我们原理都会了,现在就差一个表达式了。

 原理

图形的表达式和直线稍有不同,不再用两个端点的坐标表示,而是用起点坐标和长宽来表示。其实都是一样的,既然我们知道两个端点的坐标,那么长度不就是两个端点的横坐标之差吗?

Activesheet.AddShape 类型, X, Y, Width, Height 

类型是指你想要画什么图形,可以用下面的字符串表示,也可以直接写数字。下面为几个常用的类型。

椭圆:msoShapeOval = 9

矩形:msoShapeRectangle = 1

右箭头:msoShapeRightArrow = 33

下箭头:msoShapeDownArrow = 36

五角星:msoShape5pointStar = 92

 单系列

还是拿我们第一次的简化实例,重新下一遍,这次画一个矩形,代码如下:

Sub drawlineR2()

For i = 2 To 4

    start_x = Cells(i, Cells(i, 4)).Left

    Start_y = Cells(i, Cells(i, 4)).Top + Rows(i).Height / 3

    finish_x = Cells(i, Cells(i, 5)).Left + Cells(i, Cells(i, 5)).Width

    W = finish_x - start_x

    H = Rows(i).Height / 3

    ActiveSheet.Shapes.AddShape(1, start_x, Start_y, W, H).Select

Next

End Sub

 多系列

多个系列,如果日期有重叠,请合理设置每个系列的位置和高度,使之错开一点的间距,否则会重叠在一起,最好使用不同的填充色,这样对比更明显,如下图所示:

代码如下:

Sub drawlineR3()

For i = 2 To 4

'系列一

    start_x = Cells(i, Cells(i, 6)).Left

    Start_y = Cells(i, Cells(i, 6)).Top + Rows(i).Height / 4

    finish_x = Cells(i, Cells(i, 7)).Left + Cells(i, Cells(i, 7)).Width

    Finish_y = Start_y

    W = finish_x - start_x

    H = Rows(i).Height / 4

    ActiveSheet.Shapes.AddShape(1, start_x, Start_y, W, H).Select

    Selection.ShapeRange.Fill.ForeColor.RGB = vbRed

'系列二

    start_x = Cells(i, Cells(i, 8)).Left

    Start_y = Cells(i, Cells(i, 8)).Top + Rows(i).Height / 2

    finish_x = Cells(i, Cells(i, 9)).Left + Cells(i, Cells(i, 9)).Width

    Finish_y = Start_y

    W = finish_x - start_x

    H = Rows(i).Height / 4

    ActiveSheet.Shapes.AddShape(1, start_x, Start_y, W, H).Select

Next

End Sub

 里程碑

大家知道里程碑只是一个点,所以只要一个日期就可以了,宽度和高度大家可以根据所在的单元格进行调整,确保在单元格的中心位置就可以了。

代码如下:

Sub drawlineR4()

For i = 2 To 4

'里程碑1

    start_x = Cells(i, Cells(i, 4)).Left + Cells(i, Cells(i, 4)).Width / 3

    Start_y = Cells(i, Cells(i, 4)).Top + Rows(i).Height / 3

    W = Cells(i, Cells(i, 4)).Width / 3

    H = Rows(i).Height / 3

    ActiveSheet.Shapes.AddShape(36, start_x, Start_y, W, H).Select

    Selection.ShapeRange.Fill.ForeColor.RGB = vbRed

'里程碑2

   start_x = Cells(i, Cells(i, 5)).Left + Cells(i, Cells(i, 5)).Width / 3

    Start_y = Cells(i, Cells(i, 5)).Top + Rows(i).Height / 3

    W = Cells(i, Cells(i, 5)).Width / 3

    H = Rows(i).Height / 3

    ActiveSheet.Shapes.AddShape(92, start_x, Start_y, W, H).Select

    Selection.ShapeRange.Fill.ForeColor.RGB = vbRed

Next

End Sub

 总结

线表计划你学会了吗?有问题,欢迎在下方留言!

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
学习VBA,报表做到飞 第六章 Shapes对象 6.5 AddShape方法
Excel Excel之VBA编程常用语句300句
Excel259个常用宏
查找引用之王——Lookup函数实用技巧解读!
VBA实际应用【批量插入图片】
VBA代码非常诱人,学习有用的知识是自己的事情
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服