【发布时间】:2017-03-20 14:10:41
【问题描述】:
我有一个直径和中心固定的圆。我现在需要做的是将圆圈插入给定范围。例如,给定 11 个列框和 10 个行框要插入到 Excel 单元格中。输入给定范围后,圆将在选定范围内,其中心固定,但框的高度和宽度会有不同的测量值。我的问题是如何将圆插入具有不同高度和宽度的单元格的任何给定范围(如 11 x 10 或 9 x 12)?
我的代码:
Sub DrawCircleWithCenter()
Dim cellwidth As Single
Dim cellheight As Single
Dim ws As Worksheet
Dim rng As Range
Dim Shp2 As Shape
CellLeft = Selection.Left
CellTop = Selection.Top
ActiveSheet.Shapes.AddShape(msoShapeOval, CellLeft, CellTop, 565 / 2, 565 / 2).Select
Selection.ShapeRange.Fill.Visible = msoFalse
With Selection.ShapeRange.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 0, 0)
.Transparency = 0
End With
i = 182
Set Shp2 = ActiveSheet.Shapes.AddShape(i, CellLeft, CellTop, 20, 20)
Shp2.ShapeStyle = msoShapeStylePreset1
Set rng = ActiveWindow.VisibleRange
Selection.Left = rng.Width / 2 - Selection.Width / 2
Selection.Top = rng.Height / 2 - Selection.Height / 2
Shp2.Left = rng.Width / 2 - Shp2.Width / 2
Shp2.Top = rng.Height / 2 - Shp2.Height / 2
End Sub
【问题讨论】:
-
你的
Selection的范围是多少? -
目前,范围的选择是随机的。当我更改单元格的高度和宽度时,圆圈将在不同的范围内。是否可以在我想要的范围内制作圆圈?通过使用列 x 行。