如题,代码如下,执行后3个sheet原封不动的在那儿并未成功删除掉第一个sheet,
求助,帮忙寻找解决方法
'?获得Sheet的值.查看获得Sheet值得方法
'
'=========================================
'myString = "CreateExcel"
Dim oExcel,oBook,oSheet
Dim filePath
Dim getValue,getValue2
Dim fso,isExist,tempFolder
filePath = "C:\Users\L.H\Desktop\VBS\excel.xlsx"
'判断即将保存的文件是否已经存在于该目录,若存在,则删除该文件
Set fso = CreateObject("Scripting.FileSystemObject")
isExist = fso.FileExists(filePath)
If isExist Then
fso.DeleteFile(filePath)
End If
'建立新的Excel引用程序
Set oExcel = CreateObject("Excel.Application")
oExcel.caption="Test"
'建立新的工作空间
Set oBook = oExcel.Workbooks.add
'默认就已经建立了一个Sheet
'添加新的表
oBook.WorkSheets.add
oBook.WorkSheets.add
'选中第一个表
Set oSheet = oBook.WorkSheets.Item(1)
oSheet.Name = "MySheetofTest"
oSheet.Cells(1,1).value = "DataInThere"
Set oSheet = oBook.WorkSheets.Item(2)
oSheet.Name = "MySheetofTest2"
oSheet.Cells(1,2).value = "DataInThere2"
Set oSheet = oBook.WorkSheets.Item(3)
oSheet.Name = "MySheetofTest3"
oSheet.Cells(1,3).value = "DataInThere3"
'TODO:删除第一张表'
oBook.WorkSheets(1).Delete
oBook.SaveAs(filePath)
'获得已选中的表的第一行一列单元格的值
Set oSheet = oBook.WorkSheets.Item(1)
getValue = oSheet.Cells(1,1).Value
Set oSheet = oBook.WorkSheets.Item(2)
getValue2 = oSheet.Cells(1,2).Value
oBook.CLOSE
oExcel.quit
'释放内存
Set oSheet = Nothing
Set oBook = Nothing
Set oExcel = Nothing
MsgBox(getValue&"+"&getValue2)