Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Copying sheets

Hi,
I'm new to the Excel group, I normally post and answer on the MSProject
newsgroup but my question involves a VBA issue creating and populating
an Excel workbook from a Project macro. I need to creat a variable
number of pre-formatted worksheets into which Project data will be
exported. My VBA code currently creates the formatted worksheet and then
uses the following loop to create the requisite number of pre-formatted
worksheets:

BookNam = ActiveWorkbook.Name
Set s = Workbooks(BookNam).Worksheets(1)
For i = 1 to ShtCnt
s.Copy after:=worksheets(i)
Next i

The code works fine most of the time but not always. If I open a fresh
instance of Excel it works and generally if I make successive runs it
executes successfully. I should mention that the code is structured to
create a new workbook each time it is run. However, if I delete one of
the workbooks from a previous run, the above loop executes without error
but does not generate any copies of pre-formatted worksheets. The
Project data is exported but after the first worksheet the data is just
dumped unto blank worksheets. Does anyone have a clue why the above code
doesn't always work?

I also tried another approach by using a template worksheet file.
Apparently however, even though I create the template for sheet 1, if I
add subsequent sheets (simple insert sheet, not copy sheet), they are
not duplicates of the template. The help file doesn't seem to cover
this. Is there a way to make all sheets of a variable sheet workbook
have a pre-formatted form?

I apologize for the long winded post. Any help is greatly appreciated.
Thanks in advance.
John
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copying sheets

Well, you have left one thing to chance:

BookNam = ActiveWorkbook.Name
Set s = Workbooks(BookNam).Worksheets(1)
For i = 1 to ShtCnt
s.Copy after:=s.parent.worksheets(i)
Next i

If you use a workbook template for the workbook and create the workbook with
say 10 sheets specified for the number of sheets to go into a new workbook,
then all the sheets should be formatted the same.

--
Regards
Tom Ogilvy

"John" wrote in message
...
Hi,
I'm new to the Excel group, I normally post and answer on the MSProject
newsgroup but my question involves a VBA issue creating and populating
an Excel workbook from a Project macro. I need to creat a variable
number of pre-formatted worksheets into which Project data will be
exported. My VBA code currently creates the formatted worksheet and then
uses the following loop to create the requisite number of pre-formatted
worksheets:

BookNam = ActiveWorkbook.Name
Set s = Workbooks(BookNam).Worksheets(1)
For i = 1 to ShtCnt
s.Copy after:=worksheets(i)
Next i

The code works fine most of the time but not always. If I open a fresh
instance of Excel it works and generally if I make successive runs it
executes successfully. I should mention that the code is structured to
create a new workbook each time it is run. However, if I delete one of
the workbooks from a previous run, the above loop executes without error
but does not generate any copies of pre-formatted worksheets. The
Project data is exported but after the first worksheet the data is just
dumped unto blank worksheets. Does anyone have a clue why the above code
doesn't always work?

I also tried another approach by using a template worksheet file.
Apparently however, even though I create the template for sheet 1, if I
add subsequent sheets (simple insert sheet, not copy sheet), they are
not duplicates of the template. The help file doesn't seem to cover
this. Is there a way to make all sheets of a variable sheet workbook
have a pre-formatted form?

I apologize for the long winded post. Any help is greatly appreciated.
Thanks in advance.
John



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
Copying Sheets Stacy C[_2_] Excel Discussion (Misc queries) 3 July 27th 09 11:03 PM
Copying sheets j.ruderman[_2_] Excel Worksheet Functions 1 October 7th 08 12:41 AM
Copying Sheets LiAD Excel Worksheet Functions 1 September 10th 08 04:55 PM
Copying Sheets Ross Excel Discussion (Misc queries) 1 January 2nd 08 07:02 PM
copying sheets fastballfreddy Excel Discussion (Misc queries) 2 May 5th 06 07:20 AM


All times are GMT +1. The time now is 10:09 PM.

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

About Us

"It's about Microsoft Excel"