PC Review


Reply
Thread Tools Rate Thread

Copy Sheet Into New Workbook

 
 
Intermediate Experience User
Guest
Posts: n/a
 
      17th Oct 2009
Can someone PLEASE advise. I can't figure this out!

I have hundreds of files in one folder. I need to open specific files
within that folder and copy a sheet named "C 2009" in that workbook into a
new workbook. I need to then close the source book without saving,
save/close the new book and move on to the next open/copy/close/close and
save sequence.

The files I have to open are in column A of a worksheet (no header) called
"SourceBook" and the name I want to save the new book as is in columb B (no
header). The sheet can be named "C 2009" as it is in the source book.

So, however many rows I have "SourceBook" should be how many files I get in
the end....each with a tab that is called "C 2009." I can save all of these
files into a folder on my desktop, or anywhere else....just all together.

Please help as this is time-sensitive.

Thank you sincerely in advance.
 
Reply With Quote
 
 
 
 
Barb Reinhardt
Guest
Posts: n/a
 
      17th Oct 2009
Try something like this. You'll need to change the source and result folder
locations. This is untested.

Option Explicit

Sub Test()

Dim mySourceFolder As String
Dim myResultFolder As String
Dim myFile As String
Dim oWB As Excel.Workbook
Dim oWS As Excel.Worksheet

mySourceFolder = "C:\Documents and
Settings\barbara.reinhardt\Desktop\SourceFolder\"
myResultFolder = "C:\Documents and
Settings\barbara.reinhardt\Desktop\ResultFolder\"

myFile = Dir(mySourceFolder & "*.x*")
If myFile = "" Then Exit Sub

Do
Set oWB = Nothing
Set oWS = Nothing
On Error Resume Next
Set oWB = Workbooks.Open(mySourceFolder & myFile)
Set oWS = oWB.Worksheets("C 2009")
On Error GoTo 0

If Not oWS Is Nothing Then
'copy worksheet
oWS.SaveAs (myResultFolder & oWB.Name)
oWB.Close savechanges:=False
End If

myFile = Dir
Loop While myFile <> ""

End Sub

"Intermediate Experience User" wrote:

> Can someone PLEASE advise. I can't figure this out!
>
> I have hundreds of files in one folder. I need to open specific files
> within that folder and copy a sheet named "C 2009" in that workbook into a
> new workbook. I need to then close the source book without saving,
> save/close the new book and move on to the next open/copy/close/close and
> save sequence.
>
> The files I have to open are in column A of a worksheet (no header) called
> "SourceBook" and the name I want to save the new book as is in columb B (no
> header). The sheet can be named "C 2009" as it is in the source book.
>
> So, however many rows I have "SourceBook" should be how many files I get in
> the end....each with a tab that is called "C 2009." I can save all of these
> files into a folder on my desktop, or anywhere else....just all together.
>
> Please help as this is time-sensitive.
>
> Thank you sincerely in advance.

 
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
RE: Copy sheet cells into differnt workbook/sheet, How? Shane Devenshire Microsoft Excel Misc 1 2nd Jun 2009 11:16 PM
Copy sheet cells into differnt workbook/sheet, How? IVLUTA Microsoft Excel Misc 0 2nd Jun 2009 10:56 PM
Copy rows from multiple workbook into a different workbook (sheet) Yossy Microsoft Excel Programming 19 11th May 2008 12:34 AM
Copy Range to a New WorkBook + Name Sheet a cell Value + Name WorkBook another Celll Value Corey Microsoft Excel Programming 2 2nd Nov 2006 05:01 AM
copy a sheet to a sheet within another workbook - WITHOUT buttons from the first shee equex Microsoft Excel New Users 0 21st Feb 2006 02:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:52 PM.