| Sub drawing() ' Liuzheng welcome you to visit my homepage http://grwy.online.ha.cn/vba_excel97/ Range("a1").Select Selection.CurrentRegion.Select myrow = Selection.Rows.Count '计算行数 my = Application.InputBox("输入延伸的行数。" & Chr(13) & Chr(13) & "提示:如果输入" & myrow + 1 & ",将只绘制线条" & Chr(13) & Chr(13) & "(没有数值!)", "用VBA绘图", Default:=myrow) '弹出输入对话框 If my = Cancel Then Range("a1").Select Exit Sub End If '条件测试 ActiveSheet.Shapes.SelectAll Selection.Delete '删除所有的SHAPES ActiveSheet.Buttons.Add(245.25, 34.5, 102, 36).Select b = Selection.Name Selection.OnAction = "del_shapes" ActiveSheet.Shapes(b).Select Selection.Characters.Text = "删图" With Selection.Characters(Start:=1, Length:=3).Font .Size = 22 .Shadow = True End With '做一个删除按钮 With ActiveSheet.Shapes.BuildFreeform(msoEditingAuto, Range("a2").Value, Range("b2").Value) For i = 3 To my If Range("a" & i).Value = "" And Range("b" & i).Value = "" Then .ConvertToShape.Select Exit Sub End If .AddNodes msoSegmentCurve, msoEditingAuto, Range("a" & i).Value, Range("b" & i).Value Next i .ConvertToShape.Select End With For i = 2 To my a = Range("a" & i).Value b = Range("b" & i).Value ActiveSheet.Shapes.AddShape(msoShapeRectangle, a, b, 48.75, 21).Select Selection.Characters.Text = a & "," & b With Selection.Characters(Start:=1, Length:=6).Font .Name = "Times New Roman" End With Selection.HorizontalAlignment = xlCenter Selection.ShapeRange.Fill.Visible = msoFalse Selection.ShapeRange.Fill.Transparency = 0# Selection.ShapeRange.Line.Transparency = 0# Selection.ShapeRange.Line.Visible = msoFalse ActiveSheet.Shapes.AddShape(msoShapeOval, a, b, 1.5, 1.5).Select Selection.ShapeRange.Fill.ForeColor.SchemeColor = 5 Next I '以上是用VBA绘图 MsgBox "欢迎参观我的个人主页 http://grwy.online.ha.cn/vba_excel97/或者 http://202.102.233.10/64215258/", vbInformation, "用VBA绘图" Range("B1").Select End Sub '这段代码为:删除图片,并再做一个绘图按钮 Sub del_shapes() ActiveSheet.Shapes.SelectAll Selection.Delete Application.ScreenUpdating = False ActiveSheet.Buttons.Add(245.25, 34.5, 102, 36).Select b = Selection.Name Selection.OnAction = "drawing" ActiveSheet.Shapes(b).Select Selection.Characters.Text = "绘图" With Selection.Characters(Start:=1, Length:=3).Font .Size = 22 .Shadow = True End With Range("B1").Select End Sub |
关注此文的读者还看过: