51Testing软件测试论坛

标题: 怎么把当前的sheet 保持为excle [打印本页]

作者: FLY000    时间: 2009-7-23 20:41
标题: 怎么把当前的sheet 保持为excle
Dim src,srcExcel
Set src=CreateObject("Excel.Application")
src.visible=false
Set srcExcel=src.workbooks.open(srcExcelPath)
.....
sheetname=srcExcel.worksheets(srcsheet).name
savePath="E:\CompareExcel\Results1\" & sheetname & ".xls"
src.ActiveWorkbook.SaveAs   savePath

这个会把src所有的sheet都保持为excle,我只想保存当前activate状态的sheet,怎么办?
作者: intothestorm    时间: 2009-7-24 10:12
标题: Suppose you just save as sheet1
code comes from CodeSamplesPlus folder.
  1. ret = RemoveWorksheet(src, "Book1", "Sheet2")
  2. ret = RemoveWorksheet(src, "Book1", "Sheet3")

  3. 'The RemoveWorksheet method removes a worksheet from a workbook
  4. 'ExcelApp - the excel application which is the worksheet's parent
  5. 'workbookIdentifier - the worksheet's parent workbook identifier
  6. 'worksheetIdentifier - the worksheet's identifier
  7. Function RemoveWorksheet(ExcelApp, workbookIdentifier, worksheetIdentifier) 'As String
  8.     Dim workbook 'As Excel.workbook
  9.     Dim worksheet 'As Excel.worksheet
  10.     On Error Resume Next
  11.     Err = 0
  12.     Set workbook = ExcelApp.Workbooks(workbookIdentifier)
  13.     If Err <> 0 Then
  14.         RemoveWorksheet = "Bad Workbook Identifier"
  15.         Exit Function
  16.     End If
  17.     Set worksheet = workbook.Sheets(worksheetIdentifier)
  18.     If Err <> 0 Then
  19.         RemoveWorksheet = "Bad Worksheet Identifier"
  20.         Exit Function
  21.     End If
  22.     worksheet.Delete
  23.     RemoveWorksheet = "OK"
  24. End Function
复制代码





欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2