Esy02 1、 选定sheet1 工作表,合并A1:C1 单元格,并输入“TEST”,背景颜色设置为浅黄色,字体颜色设置为红色,字体大小设置为 10 磅。 Sub Macro1() ' Macro1 Macro ' 宏由 xu 录制,时间: 2013/3/26 ' Application.Left = 201.25 Application.Top = 61.75 Range("A1:C1").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Selection.Merge Range("A1:C1").Select ActiveCell.FormulaR1C1 = "TEST" Range("A1:C1").Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = True End With With Selection.Font .Name = "宋体" .FontStyle = "常规" .Size = 10 .Strikethrough = False .Superscript = False .Subscript = False .OutlineFont = False .Shadow = False .Underline = xlUnderlineStyleNone .ColorIndex = 3 End With With Selection.Interior .ColorIndex = 6 .Pattern = xlSolid .PatternColorIndex = xlAutomatic End With End Sub 2 在sheet1 上创建“窗体”命令按钮并指定“宏”代码 sy22,补充代码完成:从键盘输入一个整数 n,输出如下图形。其中每个“*”在单元格中水平和垂直方向都要求居中。 Sub sy22() Dim n As Integer, i As Integer, j As Integer '第 1 空 n = InputBox("输入行数") ' 从键盘输入数据并存放到变量 n Sheets("Sheet1").Cells.ClearContents '清除 sheet1 工作表中单元格的内容 For i = 1 To n ' 循环打印,输出 n 行"*" For j = 1 To 2 * i - 1 '每行输出奇数(2*i-1)个"*",如:1,3,5 个 Cells(i, n - i + j).Value = "*" Next j Next i Cells(1, n).Activate '激活 A 列 N 行的单元格 ActiveCell.CurrentRegion.Select '选定单元格所在的当前区域 With Selection .Font.Size = 16 '字体大...