|
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)
- If Err <> 0 Then
- RemoveWorksheet = "Bad Worksheet Identifier"
- Exit Function
- End If
- worksheet.Delete
- RemoveWorksheet = "OK"
- End Function
复制代码 |
|