第二次导出到EXCEL时出错!!!
由于导出到EXCEL中的数据需要做一写排版工作,就直接把要排版的代码,用EXCEL录制宏的办法把代码粘贴到VB的代码区了。具体代码为:
With xlApp
.Range("A1:AA1").Merge
.Range("A1:AA1").FormulaR1C1 = "水库下泄沿程水温温度表"
.Range("A2:AA2").Select
.Selection.Merge
.ActiveCell.FormulaR1C1 = "测量日期:" & Year(arrvalues(1, 1)) & "-" & Month(arrvalues(1, 1)) & " 测量地点:" & Combo3.Text
.Range("A3:A4").Select
.Selection.Merge
.Selection.AutoFill Destination:=Range("A3:AA4"), Type:=xlFillDefault
.Range("B3:B4").Select
.ActiveCell.FormulaR1C1 = "21"
.Selection.AutoFill Destination:=Range("B3:D4"), Type:=xlFillDefault
.Range("B3:D4").Select
.Range("E3:E4").Select
.ActiveCell.FormulaR1C1 = "0"
.Selection.AutoFill Destination:=Range("E3:Y4"), Type:=xlFillDefault
.Range("E3:Y4").Select
.Range("Z3:Z4").Select
.ActiveCell.FormulaR1C1 = "Tmax"
With .ActiveCell.Characters(Start:=2, Length:=3).Font
.Subscript = True '设置下标
End With
.Range("AA3:AA4").Select
.ActiveCell.FormulaR1C1 = "Tmin"
With .ActiveCell.Characters(Start:=2, Length:=3).Font
.Subscript = True
End With
.Range("A5").Select
.ActiveCell.FormulaR1C1 = "1"
.Range("A6").Select
.ActiveCell.FormulaR1C1 = "2"
.Range("A5:A6").Select
.Selection.AutoFill Destination:=Range("A5:A14"), Type:=xlFillDefault
.Range("A5:A14").Select
'求平均
.Range("A15").Select
.ActiveCell.FormulaR1C1 = "第一侯平均"
.Range("B15").Select
.ActiveCell.FormulaR1C1 = "=AVERAGE(R[-10]C:R[-6]C)"
.Range("B15").Select
.Selection.AutoFill Destination:=Range("B15:Y15"), Type:=xlFillDefault
.Range("B15:Y15").Select
.Range("A16").Select
.ActiveCell.FormulaR1C1 = "第二侯平均"
.Range("B16").Select
.ActiveCell.FormulaR1C1 = "=AVERAGE(R[-6]C:R[-2]C)"
.Range("B16").Select
.Selection.AutoFill Destination:=Range("B16:Y16"), Type:=xlFillDefault
.Range("B15:Y15").Select
.Range("A17").Select
.ActiveCell.FormulaR1C1 = "上旬平均"
.Range("B17").Select
.ActiveCell.FormulaR1C1 = "=AVERAGE(R[-2]C:R[-1]C)"
.Range("B17").Select
.Selection.AutoFill Destination:=Range("B17:Y17"), Type:=xlFillDefault
.Range("B17:Y17").Select
'=============================================================================
.Range("A18").Select
.ActiveCell.FormulaR1C1 = "11"
.Range("A19").Select
.ActiveCell.FormulaR1C1 = "12"
.Range("A18:A19").Select
.Selection.AutoFill Destination:=Range("A18:A27"), Type:=xlFillDefault
.Range("A18:A27").Select
.Range("A28").Select
.ActiveCell.FormulaR1C1 = "第三侯平均"
.Range("B28").Select
.ActiveCell.FormulaR1C1 = "=AVERAGE(R[-10]C:R[-6]C)"
.Range("B28").Select
.Selection.AutoFill Destination:=Range("B28:Y28"), Type:=xlFillDefault
.Range("B28:Y28").Select
.Range("A29").Select
.ActiveCell.FormulaR1C1 = "第四侯平均"
.Range("B29").Select
.ActiveCell.FormulaR1C1 = "=AVERAGE(R[-6]C:R[-2]C)"
.Range("B29").Select
.Selection.AutoFill Destination:=Range("B29:Y29"), Type:=xlFillDefault
.Range("B29:Y29").Select
.Range("A30").Select
.ActiveCell.FormulaR1C1 = "中旬平均"
.Range("B30").Select
.ActiveCell.FormulaR1C1 = "=AVERAGE(R[-2]C:R[-1]C)"
.Range("B30").Select
.Selection.AutoFill Destination:=Range("B30:Y30"), Type:=xlFillDefault
.Range("B30:Y30").Select
Set xlSheet = Nothing
Set xlBook = Nothing
xlApp.Quit
Set xlApp = Nothing
每次出错的的地方都是EXCEL 自动填充功能上面出错,显示"实时错误1004,对象'Range'的方法'_Golbal'失败"!?