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

Someone helped me with the code to merge all the files under one folder
onto one spreadsheet. However, from the code below is there a way I
can tell Excel to open a file and copy from a specific worksheet?

Application.ScreenUpdating = False
Dim FName As String
Dim WB As Workbook
Dim Dest As Range
Const FOLDERNAME = "" ChDrive FOLDERNAME
ChDir FOLDERNAME

Set Dest = Range("A2")
FName = Dir("*.xls")

Do Until FName = ""
Set WB = Workbooks.Open(FName)
WB.Worksheets(1).Rows(2).Copy Destination:=Dest
WB.Close savechanges:=False
Set Dest = Dest(2, 1)
FName = Dir()
Loop
End Sub

Thank you!!


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Merging Files

WB.Worksheets(1).Rows(2).Copy Destination:=Dest

This will copy from the first worksheet( It use the sheet index)

If the worksheet names in the files have the same name you can use this
WB.Worksheets("yoursheet").Rows(2).Copy Destination:=Dest

I have also a example on this page
http://www.rondebruin.nl/copy3.htm




--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"rglasunow " wrote in message ...
Someone helped me with the code to merge all the files under one folder
onto one spreadsheet. However, from the code below is there a way I
can tell Excel to open a file and copy from a specific worksheet?

Application.ScreenUpdating = False
Dim FName As String
Dim WB As Workbook
Dim Dest As Range
Const FOLDERNAME = "" ChDrive FOLDERNAME
ChDir FOLDERNAME

Set Dest = Range("A2")
FName = Dir("*.xls")

Do Until FName = ""
Set WB = Workbooks.Open(FName)
WB.Worksheets(1).Rows(2).Copy Destination:=Dest
WB.Close savechanges:=False
Set Dest = Dest(2, 1)
FName = Dir()
Loop
End Sub

Thank you!!


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Merging Files

Thanks for your response. I realized one more problem. The sheet that
I want to copy is hidden. I tried to add some code to no avail.

Sub MergeFiles()
Application.ScreenUpdating = False
Dim FName As String
Dim WB As Workbook
Dim Dest As Range
Const FOLDERNAME = "C:\Excel Data"
ChDrive FOLDERNAME
ChDir FOLDERNAME

Set Dest = Range("A2")
FName = Dir("*.xls")
If Len(FNames) = 0 Then
MsgBox "No files in the Directory"
Exit Sub
End If

Do Until FName = "" '<<< Change do until file!!
Set WB = Workbooks.Open(FName)
Windows(FName).Activate
Sheets("Data").Visible = True
WB.Worksheets("Data").Rows(2).Copy Destination:=Dest
WB.Close savechanges:=False
Set Dest = Dest(2, 1)
FName = Dir()
Loop
End Sub

Also I think that I need to do a copy/paste special when bringing the
data over. I couldn't figure out where I could put the code on this as
it looks like to me that this says to copy the data from the sheet to
the destination on the other sheet.

Any sugestions?

Thank you!


---
Message posted from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Merging Files

Please ignore my previous posting. I have found what the problem is.
However, I'm not sure how to fix it. I want to copy the 2nd row in al
the files and paste them in an on going spreadsheet on the master file
What is happening is it's pulling the next row down instead. S
instead of having cell B5 for all of column A it's going B5, B6, B7
etc...
Thanks,
RYa

--
Message posted from http://www.ExcelForum.com

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
Merging 2 files Distribution list - Contacts Module Excel Discussion (Misc queries) 1 October 25th 08 02:48 AM
merging files Maaz New Users to Excel 3 March 1st 07 04:24 PM
merging zip files! via135 Excel Discussion (Misc queries) 2 November 19th 06 05:32 PM
merging two files mcap Excel Discussion (Misc queries) 3 April 9th 06 07:28 PM
Merging two different files justinfisher Excel Discussion (Misc queries) 0 January 21st 05 08:53 PM


All times are GMT +1. The time now is 01:20 AM.

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"