Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default ***PLease help. Need to Merge directory of files into one file.***

I have a bunch of excel files stored in c:/temp. I want to merge all of
these files into one excel spreadsheet.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default ***PLease help. Need to Merge directory of files into one file.***

Sub consolidatebooks()
Dim sh as Worksheet
Dim sPath as String, sName as String
Dim bk as workbook
set sh = Activesheet
sh.cells.clearcontents
sPath = "C:\Myfolder\"
sName = dir(sPath & "*.xls")
do while sName < ""
set bk = workbooks.Open(sPath & sname)
' copy sheets?
'bk.worksheets.copy After:= _
thisworkbook.Worksheets(thisworbook.worksheets.cou nt)
' copy some data
' bk.worksheets(1).Range("A1").currentRegion.copy _
sh.cells(rows.count,1).End(xlup)(2)
bk.close SaveChanges:=False
sname = dir()
Loop
End Sub

--
Regards,
Tom Ogilvy

"Shani" wrote:

I have a bunch of excel files stored in c:/temp. I want to merge all of
these files into one excel spreadsheet.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default ***PLease help. Need to Merge directory of files into one file.***

This code gets all matching files from a directory - change my message
box to whatever you need it to do (insert file by the sound of it!)


Sub lookin()



Set fs = Application.FileSearch
Dim newbook, curbook, MyCount, myrange
With fs
.lookin = "c:\temp\usb"
'LookIn should be changed to the location you want to use
..SearchSubFolders = True 'assuming you DO want to search subfolders

.Filename = "*.xls"
'if you are looking for other than DOC files, alter the line above
If .Execute(SortBy:=msoSortByFileName,
SortOrder:=msoSortOrderAscending) 0 Then
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)

Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default ***PLease help. Need to Merge directory of files into one file.***

doesn't do anything

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default ***PLease help. Need to Merge directory of files into one file.***

this doesnt do anything



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default ***PLease help. Need to Merge directory of files into one file.***

there is a syntax error.


If .Execute(SortBy:=msoSortByFileName

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default ***PLease help. Need to Merge directory of files into one file.***

Tom left the definition of Merge to you.

do while sName < ""
set bk = workbooks.Open(sPath & sname)
' copy sheets?
'bk.worksheets.copy After:= _
thisworkbook.Worksheets(thisworbook.worksheets.cou nt)
' copy some data
' bk.worksheets(1).Range("A1").currentRegion.copy _
sh.cells(rows.count,1).End(xlup)(2)
bk.close SaveChanges:=False
sname = dir()
Loop

The top part of this portion of the code copies all the worksheets in each
workbook to this workbook.

The bottom part of this portion of the code copies all the data in each sheet to
a single sheet within this new workbook.

Since you didn't give any hint about what you meant by merge, Tom left it up to
you to decide.

You'll have to uncomment the lines that do the type of work you want.

' copy sheets?
' copy some data

Are instructions to you--don't uncomment them.

And since you didn't give any rules, Tom's code uses Column A to determine the
next available cell and assumes that all your data in each sheet is contiguous.

======
Ps.

I think you meant:

Tom, Thank you for your response, but this doesn't seem to do anything when I
try it. What can I do to make it work the way I want?

And then you should give a little more info about how you want it to work.






Shani wrote:

this doesnt do anything


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default ***PLease help. Need to Merge directory of files into one file

It doesn't open and close the workbooks in the directory?

I gave you some choices, possibly you are frozen by indecision.

Work with Aiden.

--
Regards,
Tom Ogilvy


"Shani" wrote:

this doesnt do anything


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default ***PLease help. Need to Merge directory of files into one file

there is a syntax error.


If .Execute(SortBy:=msoSortByFileName


given this post, how could you post your first post to Aiden.

Perhaps this isn't a serious request and you are just toying with use.
Enjoy. <g

by the way, you just have copied the code improperly and haven't corrected
for wordwrap.

--
Regards,
Tom Ogilvy


"Shani" wrote:

there is a syntax error.


If .Execute(SortBy:=msoSortByFileName


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
Merge Like Files into 1 File Kentucky Bill Excel Discussion (Misc queries) 1 March 22nd 10 07:19 PM
How Merge 2 files with same acc# in each file Kate Excel Discussion (Misc queries) 0 January 10th 08 05:51 PM
how do you merge many files into one file with several worksheets? AirportGal Excel Discussion (Misc queries) 1 August 2nd 07 11:52 AM
how i can merge more than two excel files in one file. Fahad Sadiq New Users to Excel 3 February 16th 05 07:23 PM
Check if directory empty OR no of files in directory. Michael Beckinsale Excel Programming 2 December 4th 03 10:12 PM


All times are GMT +1. The time now is 04:51 PM.

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"