|  

» Create new workbooks using VBA in Microsoft Excel

VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions With the function below you can create new workbooks with up to 255 new worksheets.
You can use the macro like this if you want to create a new workbook with 10 worksheets:
Set wb = NewWorkbook(10) 

Function NewWorkbook(wsCount As Integer) As Workbook
' creates a new workbook with wsCount (1 to 255) worksheets
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

Rate This Tip
12 34 5
Rating: 3.24     Views: 142730
No comments have been submitted.
Click here to post comment
For Registered Users
Name
Comment Title
Comments