标题: 怎么把当前的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.
ret = RemoveWorksheet(src, "Book1", "Sheet2")
ret = RemoveWorksheet(src, "Book1", "Sheet3")
'The RemoveWorksheet method removes a worksheet from a workbook
'ExcelApp - the excel application which is the worksheet's parent
'workbookIdentifier - the worksheet's parent workbook identifier
'worksheetIdentifier - the worksheet's identifier
Function RemoveWorksheet(ExcelApp, workbookIdentifier, worksheetIdentifier) 'As String
Dim workbook 'As Excel.workbook
Dim worksheet 'As Excel.worksheet
On Error Resume Next
Err = 0
Set workbook = ExcelApp.Workbooks(workbookIdentifier)
If Err <> 0 Then
RemoveWorksheet = "Bad Workbook Identifier"
Exit Function
End If
Set worksheet = workbook.Sheets(worksheetIdentifier)