excel-vba應(yīng)用示例之創(chuàng)建新的工作簿
2007-01-31 16:43
創(chuàng)建新的工作簿 Sub testNewWorkbook() MsgBox "創(chuàng)建一個(gè)帶有10個(gè)工作表的新工作簿" Dim wb as Workbook Set wb = NewWorkbook(10) End Sub ‘- - - - - - - - - - - - - - - - - - - - - - - Function NewWorkbook(wsCount As Integer) As Workbook '創(chuàng)建帶有由變量wsCount提定數(shù)量工作表的工作簿,,工作表數(shù)在1至255之間 Dim OriginalWorksheetCount As Long Set NewWorkbook = Nothing If wsCount < 1 Or wsCount > 255 Then Exit Function OriginalWorksheetCount = Application.SheetsInNewWorkbook Application.SheetsInNewWorkbook = wsCount Set NewWorkbook = Workbooks.Add Application.SheetsInNewWorkbook = OriginalWorksheetCount End Function 示例說(shuō)明:自定義函數(shù)NewWorkbook可以創(chuàng)建最多帶有255個(gè)工作表的工作簿,。本測(cè)試示例創(chuàng)建一個(gè)帶有10個(gè)工作表的新工作簿,。
|
|