文章预览
学习Excel技术,关注微信公众号: excelperfect 标签: VBA 下面的程序在工作表当前单元格中添加一个矩形,并指定单击该矩形时要执行的宏。可以指定矩形的大小,以及矩形中的文本。 代码如下: Sub autoAdd_Rectangle_Macros() Dim ws As Worksheet Dim sh As Object Dim sText As String Dim sDimensions As String Dim rDimensions As Range Dim iColor As Integer Dim s As String On Error Resume Next Set ws = ActiveSheet sDimensions = Trim(Application.InputBox("请输入形状的大小 (行 x 列)", "形状大小", "3x3", , , , , 2)) iColor = Trim(Application.InputBox("请输入形状的颜色: 1 =蓝色, 2 =绿色, 3 =红色", "形状颜色填充", "2", , , , , 1)) iColor = WorksheetFunction.Min(iColor, 3) iColor = WorksheetFunction.Max(iColor, 0) Set rDimensions = Selection.Cells(1).Resize(CDbl(Split(sDimensions, "x")(0)), CDbl(Split(sDimens
………………………………