Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Macro to copy current worksheet to pre-defined wookbook

Hi All,

I have developed a monthly timesheet workbook with a worksheet for each
week. All workers will use this and as each week is completed, i want them to
run a macro to copy the CURRENT WORKSHEET to a supervisor's workbook. The
super's book will then have that week from all workers in one location so he
can just open his book and see all the worker's weeks.

In their worksheets, the worker's names are in cell B1 so it would be really
nice if the copies of the worker's worksheets were renamed to the name in
cell B1.

Thanks in advance for any help or suggestions.

Sammy
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Macro to copy current worksheet to pre-defined wookbook

I wouldn't have the workers opening a supervisors workbook. the better way
of doing this is to have a macro in each workers worksheet that saves the
files in a directory. then have the supervisor run a macro to gether or the
time sheets in his workbook.

You can set up weekly folders in adavance and then have the workers save the
file into the correct weekly directory based on the date.

"sammy" wrote:

Hi All,

I have developed a monthly timesheet workbook with a worksheet for each
week. All workers will use this and as each week is completed, i want them to
run a macro to copy the CURRENT WORKSHEET to a supervisor's workbook. The
super's book will then have that week from all workers in one location so he
can just open his book and see all the worker's weeks.

In their worksheets, the worker's names are in cell B1 so it would be really
nice if the copies of the worker's worksheets were renamed to the name in
cell B1.

Thanks in advance for any help or suggestions.

Sammy

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Macro to copy current worksheet to pre-defined wookbook

Hi Joel,

Thanks for the very quick response. And i like the idea of just copying the
worksheets to a directory but how can i copy only one worksheet from a book
with several sheets?

Sammy

"Joel" wrote:

I wouldn't have the workers opening a supervisors workbook. the better way
of doing this is to have a macro in each workers worksheet that saves the
files in a directory. then have the supervisor run a macro to gether or the
time sheets in his workbook.

You can set up weekly folders in adavance and then have the workers save the
file into the correct weekly directory based on the date.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Macro to copy current worksheet to pre-defined wookbook

The little tricks that most people don't know. if yo do a copy without using
before or after a new workbook is created.

ActiveSheet.Copy
Set newbk = ActiveWorkbook 'this is the copied sheet with one worksheet
newbk.SaveAs Filename:="c:\temp\book1.xls"



"sammy" wrote:

Hi Joel,

Thanks for the very quick response. And i like the idea of just copying the
worksheets to a directory but how can i copy only one worksheet from a book
with several sheets?

Sammy

"Joel" wrote:

I wouldn't have the workers opening a supervisors workbook. the better way
of doing this is to have a macro in each workers worksheet that saves the
files in a directory. then have the supervisor run a macro to gether or the
time sheets in his workbook.

You can set up weekly folders in adavance and then have the workers save the
file into the correct weekly directory based on the date.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Macro to copy current worksheet to pre-defined wookbook

Okay, now i'm learning something. But after more consideration, i think i
want all the sheets from all workers from one week to be copied into the same
book. Is it possible to check if a target book exists and if not create it?
This way the super has a week to rename this repository then the first worker
attempting to copy the next week's sheet will actually create a new
repository. Of course, if the repository book does exist, the worker's sheet
will just be copied into it.

"Joel" wrote:

The little tricks that most people don't know. if yo do a copy without using
before or after a new workbook is created.

ActiveSheet.Copy
Set newbk = ActiveWorkbook 'this is the copied sheet with one worksheet
newbk.SaveAs Filename:="c:\temp\book1.xls"



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Macro to copy current worksheet to pre-defined wookbook


You can use the DIR() function.

Folder = "C:\"
BookName = "book1.xls"
Fname = dir(Folder & BookName)
if FName = "" then
set newbk = workbooks.add
else
set newbk = workbooks.open(Folder & BookName)
end if


My prefernce to this problem is to have a seperate workbook for each
employee for 1 calander year. Each week will be a different worksheet which
will be added each week. This way when a supervisor need to review an
employees times sheets in is all in one workbook. The supervisor workbook
will have a macro to open and copy all the employees workbooks and copy the
latest worksheet to his book for the summary.

The problem is a workbook can only be opened for writing by one person. if
two people try to write at one time one of the employees will get a READ ONLY
copy of the workbook and won't be able to save the information. I also like
to set up a different directory for each department when you have more than
one supervisor.
"sammy" wrote:

Okay, now i'm learning something. But after more consideration, i think i
want all the sheets from all workers from one week to be copied into the same
book. Is it possible to check if a target book exists and if not create it?
This way the super has a week to rename this repository then the first worker
attempting to copy the next week's sheet will actually create a new
repository. Of course, if the repository book does exist, the worker's sheet
will just be copied into it.

"Joel" wrote:

The little tricks that most people don't know. if yo do a copy without using
before or after a new workbook is created.

ActiveSheet.Copy
Set newbk = ActiveWorkbook 'this is the copied sheet with one worksheet
newbk.SaveAs Filename:="c:\temp\book1.xls"

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Macro to copy current worksheet to pre-defined wookbook

Hi Joel,

I really appreciate your help with this. I tried to implement your code,
both old and new, but it doesn't work. I'm sure when i added the snippets
together it is causing it to fail. This is what i have. Will you please help
me some more?

Sub EndWeek()

ActiveSheet.Copy

Folder = "C:\junk\"
BookName = "book1.xls"
FName = Dir(Folder & BookName)

If FName = "" Then
Set newbk = Workbooks.Add
Else
Set newbk = Workbooks.Open(Folder & BookName)
End If

Set newbk = ActiveWorkbook 'this is the copied sheet with one worksheet
newbk.SaveAs Filename:=FName
newbk.Close

End Sub

"Joel" wrote:


You can use the DIR() function.

Folder = "C:\"
BookName = "book1.xls"
Fname = dir(Folder & BookName)
if FName = "" then
set newbk = workbooks.add
else
set newbk = workbooks.open(Folder & BookName)
end if


My prefernce to this problem is to have a seperate workbook for each
employee for 1 calander year. Each week will be a different worksheet which
will be added each week. This way when a supervisor need to review an
employees times sheets in is all in one workbook. The supervisor workbook
will have a macro to open and copy all the employees workbooks and copy the
latest worksheet to his book for the summary.

The problem is a workbook can only be opened for writing by one person. if
two people try to write at one time one of the employees will get a READ ONLY
copy of the workbook and won't be able to save the information. I also like
to set up a different directory for each department when you have more than
one supervisor.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Macro to copy current worksheet to pre-defined wookbook

The code worked if the file existed and didn't work when the file wasn't there.

Just change 1 statement

newbk.SaveAs Filename:=BookName

The old code had FName instead of BookName.

"sammy" wrote:

Hi Joel,

I really appreciate your help with this. I tried to implement your code,
both old and new, but it doesn't work. I'm sure when i added the snippets
together it is causing it to fail. This is what i have. Will you please help
me some more?

Sub EndWeek()

ActiveSheet.Copy

Folder = "C:\junk\"
BookName = "book1.xls"
FName = Dir(Folder & BookName)

If FName = "" Then
Set newbk = Workbooks.Add
Else
Set newbk = Workbooks.Open(Folder & BookName)
End If

Set newbk = ActiveWorkbook 'this is the copied sheet with one worksheet
newbk.SaveAs Filename:=FName
newbk.Close

End Sub

"Joel" wrote:


You can use the DIR() function.

Folder = "C:\"
BookName = "book1.xls"
Fname = dir(Folder & BookName)
if FName = "" then
set newbk = workbooks.add
else
set newbk = workbooks.open(Folder & BookName)
end if


My prefernce to this problem is to have a seperate workbook for each
employee for 1 calander year. Each week will be a different worksheet which
will be added each week. This way when a supervisor need to review an
employees times sheets in is all in one workbook. The supervisor workbook
will have a macro to open and copy all the employees workbooks and copy the
latest worksheet to his book for the summary.

The problem is a workbook can only be opened for writing by one person. if
two people try to write at one time one of the employees will get a READ ONLY
copy of the workbook and won't be able to save the information. I also like
to set up a different directory for each department when you have more than
one supervisor.

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Macro to copy current worksheet to pre-defined wookbook

Thanks Joel, that gets it done.

"Joel" wrote:

The code worked if the file existed and didn't work when the file wasn't there.

Just change 1 statement

newbk.SaveAs Filename:=BookName

The old code had FName instead of BookName.

"sammy" wrote:

Hi Joel,

I really appreciate your help with this. I tried to implement your code,
both old and new, but it doesn't work. I'm sure when i added the snippets
together it is causing it to fail. This is what i have. Will you please help
me some more?

Sub EndWeek()

ActiveSheet.Copy

Folder = "C:\junk\"
BookName = "book1.xls"
FName = Dir(Folder & BookName)

If FName = "" Then
Set newbk = Workbooks.Add
Else
Set newbk = Workbooks.Open(Folder & BookName)
End If

Set newbk = ActiveWorkbook 'this is the copied sheet with one worksheet
newbk.SaveAs Filename:=FName
newbk.Close

End Sub

"Joel" wrote:


You can use the DIR() function.

Folder = "C:\"
BookName = "book1.xls"
Fname = dir(Folder & BookName)
if FName = "" then
set newbk = workbooks.add
else
set newbk = workbooks.open(Folder & BookName)
end if


My prefernce to this problem is to have a seperate workbook for each
employee for 1 calander year. Each week will be a different worksheet which
will be added each week. This way when a supervisor need to review an
employees times sheets in is all in one workbook. The supervisor workbook
will have a macro to open and copy all the employees workbooks and copy the
latest worksheet to his book for the summary.

The problem is a workbook can only be opened for writing by one person. if
two people try to write at one time one of the employees will get a READ ONLY
copy of the workbook and won't be able to save the information. I also like
to set up a different directory for each department when you have more than
one supervisor.

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
Copy worksheet into current workbook Gerard Excel Discussion (Misc queries) 0 February 19th 10 03:31 PM
how can I close a worksheet without exiting the wookbook Grumpy Ump 1 Excel Discussion (Misc queries) 2 September 21st 07 11:15 PM
compare name and copy to current worksheet Mikke Excel Programming 0 May 13th 06 04:03 PM
Copy worksheet excluding defined name ranges Thomas Smith[_2_] Excel Programming 2 July 11th 05 08:45 AM
Create Copy of Current Worksheet Birdy92 Excel Programming 1 January 14th 04 03:36 AM


All times are GMT +1. The time now is 05:44 AM.

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"