Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default 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


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default 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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default 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


.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can i open a second workbook using a vba code [email protected] uk Excel Discussion (Misc queries) 10 November 28th 09 05:42 PM
Need VB code for workbook open to open a link Daniel Baker Excel Discussion (Misc queries) 2 August 18th 06 01:30 AM
Need VBA Code to Open a Workbook in read only zulfer7 Excel Discussion (Misc queries) 1 July 10th 06 11:00 PM
Workbook Open code Mike Tomasura Excel Programming 0 August 1st 03 05:32 PM
Workbook Open code Chip Pearson Excel Programming 0 August 1st 03 05:29 PM


All times are GMT +1. The time now is 06:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"