If CheckSheet(strSheetName, strWorkBook, xlCreateApp) = False Then
Set xlCreateSheet = xlCreateApp.Worksheets.Add
xlCreateSheet.Name = strSheetName
xlCreateApp.ActiveWorkbook.Save
CreateSheet = True
Set xlCreateSheet = Nothing
Else
'MsgBox strSheetName & "工作表已存在!"
CreateSheet = False
Set xlCreateSheet = Nothing
End If
ElseIf CreateMethod = 2 Then
If CheckSheet(strSheetName, strWorkBook, xlCreateApp) = True Then
Set xlCreateSheet = xlCreateApp.Worksheets(strSheetName)
xlCreateSheet.Cells.Select
xlCreateSheet.Cells.Delete
xlCreateApp.ActiveWorkbook.Save
CreateSheet = True
Set xlCreateSheet = Nothing
Else
'MsgBox strSheetName & "工作表不存在!"
CreateSheet = False
Set xlCreateSheet = Nothing
End If
End If
End If
End Function
'刪除工作表
Function DeleteSheet(ByVal strSheetName As String, ByVal strWorkBook As String, xlDeleteApp As Excel.Application) As Boolean
Dim i As Integer
Dim xlDeleteSheet As Excel.Worksheet
If CheckFile(strWorkBook) Then
If CheckSheet(strSheetName, strWorkBook, xlDeleteApp) = True Then
xlDeleteApp.Workbooks.Open (strWorkBook)
If xlDeleteApp.Worksheets.Count = 1 Then
MsgBox "工作薄不能全部刪除," & strSheetName & "是最后一個工作表!"
DeleteSheet = False
Exit Function
End If
相關(guān)推薦:2011計算機(jī)等級考試二級VB考點(diǎn)及習(xí)題匯總
北京 | 天津 | 上海 | 江蘇 | 山東 |
安徽 | 浙江 | 江西 | 福建 | 深圳 |
廣東 | 河北 | 湖南 | 廣西 | 河南 |
海南 | 湖北 | 四川 | 重慶 | 云南 |
貴州 | 西藏 | 新疆 | 陜西 | 山西 |
寧夏 | 甘肅 | 青海 | 遼寧 | 吉林 |
黑龍江 | 內(nèi)蒙古 |