PC Review


Reply
Thread Tools Rate Thread

How to add additional worksheets to a directory of workbooks

 
 
ibbm
Guest
Posts: n/a
 
      21st May 2009
Hi there,

I have a workbook for every employee in a directory which contains their
excel timesheets. I now need to add more worksheets for the next 6 months.
I have a workbook with a colum of names of the sheets I want to add and
another column of the employees names. How do I do this.

This is my macro so far

Sub UpdateTimeSheets()
Application.ScreenUpdating = False
Set FS = Application.FileSearch
strPath = "c:\TimeSheets"

n = 1
y = 1
For y = 1 To 4
With FS
.NewSearch
.LookIn = strPath
.SearchSubFolders = True
.Filename = ThisWorkbook.Sheets(2).Cells(y, 1)
iCount = .Execute

' strMessage = Format(iCount, "0 ""Files Found""")

For Each vaFileName In .FoundFiles
Set wb = Workbooks.Open(vaFileName)
' update workbook with additional worksheets with the names from
the 'period names' worksheet in column A rows 2 to 7
For x = 2 To 7
Set ws = Worksheets.Add(After:=Sheets(Sheets.Count))
ws.Name = ThisWorkbook.Sheets(1).Cells(x, 1)
wb.Close True ' save and close
Next x ' get next employees timesheet

Next
End With
Next y

Application.ScreenUpdating = True


End Sub

This opens up the first employee file but then it says it cannot rename the
worksheet.

Thanks in advance for your help.

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      21st May 2009
Maybe you're trying to use a name that is invalid.

There are certain names that can't be used (length of name has to be less than
32 characters, no duplicate names, no sheet named History in xl97+).

There are certain characters that cannot be used:
\, /, *, :, [, ]

So what is the name that's failing?

ibbm wrote:
>
> Hi there,
>
> I have a workbook for every employee in a directory which contains their
> excel timesheets. I now need to add more worksheets for the next 6 months.
> I have a workbook with a colum of names of the sheets I want to add and
> another column of the employees names. How do I do this.
>
> This is my macro so far
>
> Sub UpdateTimeSheets()
> Application.ScreenUpdating = False
> Set FS = Application.FileSearch
> strPath = "c:\TimeSheets"
>
> n = 1
> y = 1
> For y = 1 To 4
> With FS
> .NewSearch
> .LookIn = strPath
> .SearchSubFolders = True
> .Filename = ThisWorkbook.Sheets(2).Cells(y, 1)
> iCount = .Execute
>
> ' strMessage = Format(iCount, "0 ""Files Found""")
>
> For Each vaFileName In .FoundFiles
> Set wb = Workbooks.Open(vaFileName)
> ' update workbook with additional worksheets with the names from
> the 'period names' worksheet in column A rows 2 to 7
> For x = 2 To 7
> Set ws = Worksheets.Add(After:=Sheets(Sheets.Count))
> ws.Name = ThisWorkbook.Sheets(1).Cells(x, 1)
> wb.Close True ' save and close
> Next x ' get next employees timesheet
>
> Next
> End With
> Next y
>
> Application.ScreenUpdating = True
>
>
> End Sub
>
> This opens up the first employee file but then it says it cannot rename the
> worksheet.
>
> Thanks in advance for your help.


--

Dave Peterson
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding additional worksheets to an existing template Mike F Microsoft Excel Misc 2 20th Nov 2008 07:18 PM
Copy/ move selected data from workbooks to seperate worksheets or workbooks Positive Microsoft Excel Worksheet Functions 1 30th Aug 2007 04:54 PM
Additional new Directory =?Utf-8?B?R1NQ?= Windows XP Help 1 23rd Jul 2006 04:52 PM
retain formula in additional workbooks =?Utf-8?B?THluY2g=?= Microsoft Excel New Users 1 30th Jan 2006 08:11 PM
Filter list on additional worksheets Annabelle Microsoft Excel Misc 2 1st Jul 2005 12:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:23 PM.