Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 启动代码时接收1004错误_Excel_Vba - Fatal编程技术网

Excel 启动代码时接收1004错误

Excel 启动代码时接收1004错误,excel,vba,Excel,Vba,我正在尝试执行一些小程序,我有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").Fon

我正在尝试执行一些小程序,我有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
谁能告诉我,怎么了?谢谢

试试看

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

以下是您要查找的内容:

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