ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code to open new workbook (https://www.excelbanter.com/excel-programming/288676-code-open-new-workbook.html)

Andrew[_27_]

Code to open new workbook
 
Ladies & Gents,

I wish to update my macros to open new workbooks with the required number of
spreadsheets. I have the following function, but am unable to get it to
work (I'm not too confidant with functions);

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

Can anybody give me some clues either on how to get this function to work
within a macro? Or does anyone have some code that will open a new workbook
with a specified number of spreadsheet?


Thanks in advance
Andrew



Brad[_10_]

Code to open new workbook
 
That function worked for me. Just need a subroutine to
call it.

Sub CreateWorkbook()
Dim wbkNew As Workbook
Set wbkNew = NewWorkbook(20)
End Sub

-Brad
-----Original Message-----
Ladies & Gents,

I wish to update my macros to open new workbooks with the

required number of
spreadsheets. I have the following function, but am

unable to get it to
work (I'm not too confidant with functions);

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

Can anybody give me some clues either on how to get this

function to work
within a macro? Or does anyone have some code that will

open a new workbook
with a specified number of spreadsheet?


Thanks in advance
Andrew


.


Beto[_3_]

Code to open new workbook
 
Andrew wrote:

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

Can anybody give me some clues either on how to get this function to work
within a macro?


Just call it from another procedu

Sub Create_A_New_Workbook_With_10_Sheets()
NewWorkbook 10
End Sub

--
Beto
Reply: Erase between the dot (inclusive) and the @.
Responder: Borra la frase obvia y el punto previo.


Andrew[_27_]

Code to open new workbook
 
Brad & Beto,

Thanks for your assistance. I guess my problem was that I've never included
a function in any of my macros before. I'll give it a go, and see what I
come up with.


Thanks again.
Andrew

"Brad" wrote in message
...
That function worked for me. Just need a subroutine to
call it.

Sub CreateWorkbook()
Dim wbkNew As Workbook
Set wbkNew = NewWorkbook(20)
End Sub

-Brad
-----Original Message-----
Ladies & Gents,

I wish to update my macros to open new workbooks with the

required number of
spreadsheets. I have the following function, but am

unable to get it to
work (I'm not too confidant with functions);

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

Can anybody give me some clues either on how to get this

function to work
within a macro? Or does anyone have some code that will

open a new workbook
with a specified number of spreadsheet?


Thanks in advance
Andrew


.





All times are GMT +1. The time now is 08:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com