Public
Function WorksheetExist(name
As
String)
As Excel.Worksheet
Try
Dim existSheet
As Excel.Worksheet = Globals.ThisWorkbook.Sheets(name)
Return existSheet
Catch ex
As Exception
Return
Nothing
End
Try
End Function
Private
Function CreatWorksheet(
ByRef book
As Excel.Workbook,
ByRef name
As
String)
As Excel.Worksheet
Dim newSheet
As Excel.Worksheet = book.Sheets.Add(After:=book.Worksheets(book.Sheets.Count))
Try
newSheet.Name = name
Return newSheet
Catch ex
As Exception
MsgBox(
"
""
" + name +
"
""
" +
"
不能被用做excel工做表(sheet)名稱
")
newSheet.Delete()
Return
Nothing
End
Try
End Function
Dim algoSheet
As Excel.Worksheet = Globals.ThisWorkbook.WorksheetExist(name)
If algoSheet
Is
Nothing
Then
algoSheet = CreatWorksheet(Globals.ThisWorkbook.Application.Workbooks(Globals.ThisWorkbook.Name), name)
If (algoSheet
Is
Nothing)
Then
Continue
For
End
If
End
If