Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy Sheet Into New Workbook

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Copy Sheet Into New Workbook

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
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 sheet cells into differnt workbook/sheet, How? IVLUTA Excel Discussion (Misc queries) 2 June 2nd 09 11:16 PM
Copy rows from multiple workbook into a different workbook (sheet) Yossy Excel Programming 19 May 11th 08 12:34 AM
Copy Sheet from One workbook to another EXISTING workbook Ken Soenen Excel Programming 0 February 12th 06 04:07 PM
automatic copy and paste from sheet to sheet in a workbook ramseyjramseyj Excel Programming 6 December 11th 04 12:37 AM


All times are GMT +1. The time now is 02:13 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"