请高手帮忙.我写的VB出现问题
第一个按钮代码Private Sub Command1_Click()
Dim EXAPP As Excel.Application
Dim WB As Excel.Workbook
Dim sht As Excel.Worksheet
Set EXAPP = CreateObject("excel.application")
Set WB = EXAPP.Workbooks.Open("d:\成绩表.xls")
Set sht = WB.Worksheets("Sheet1")
Range("N2").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-8]:RC[-1])"
Range("N2").Select
Selection.AutoFill Destination:=Range("N2:N641"), Type:=xlFillDefault
Range("N2:N641").Select
ActiveWindow.SmallScroll Down:=-9
Form1.Caption = sht.Range("B5").Value '从表格取值
'WB.Save'保存编辑后的文件
WB.Close
Set sht = Nothing
Set WB = Nothing
Set EXAPP = Nothing
End Sub
第二个按钮代码
Private Sub Command2_Click()
Dim EXAPP As Excel.Application
Dim WB As Excel.Workbook
Dim sht As Excel.Worksheet
Set EXAPP = CreateObject("excel.application")
Set WB = EXAPP.Workbooks.Open("d:\成绩表.xls")
Set sht = WB.Worksheets("总表")
Range("A2:V800").Select
Selection.Sort Key1:=Range("T3"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
:=xlPinYin, DataOption1:=xlSortNormal
Set sht = Nothing
Set WB = Nothing
Set EXAPP = Nothing
End Sub
只要执行第二个按钮,红色部分就提示错误,是什么原因请高手帮忙下