启动代码时收到1004错误

时间:2014-11-09 22:09:25

标签: excel-vba vba excel

我正在尝试执行一些小程序,我有1004错误 这是我的代码

Sub program2()
    With Worksheets("Test")
        .Range("a1").Value = "Test"
        .Range("b1") = "Test"
        .Cells(2, 2) = "Test"
        .Range("b2").Font.ColorIndex = 3
    End With
    With Range("a1:b1").Font = 9
        .Bold = True
        .Name = "Arial"
        .Size = 16
        .ColorIndex = 5
    End With
End Sub

有人能告诉我,有什么不对吗?感谢

2 个答案:

答案 0 :(得分:0)

尝试,

With Range("a1:b1").Font
    '.Size = 9   ' 9 or 16; not both
    .Bold = True
    .Name = "Arial"
    .Size = 16
    .ColorIndex = 5
End With

答案 1 :(得分:0)

以下是您正在寻找的内容:

Sub program2()
    With Worksheets("Test")
        .Range("a1").Value = "Test"
        .Range("b1") = "Test"
        .Cells(2, 2) = "Test"
        .Range("b2").Font.ColorIndex = 3
    End With
    With Range("a1:b1").Font
        .Bold = True
        .Name = "Arial"
        .Size = 16
        .ColorIndex = 5
    End With
End Sub