LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 247
Default How to determine How many files in specified directory

The MASTER (Destination) WB will have only ONE WS.
Each Source WB has only ONE WS
Each Source WS in each WB has the same number of Columns
Each Source WS in each WB has Different number of rows.
Each Source WB will be named by number, in order, from
1.xls thru 12.xls - EXPECT that usually will have 4 or 5 Source WB's
All (ONLY) WB's for this process will be in C:\DATA

How can the number of WB's be determined automatically, and then
how can the required processes be activated for only that number of WB'sfiles.

Sub Combine_M2M_Extracts()

' M2M-Master.xlt file has been opened
' Shows as M2M-Master1.xls - Save M2M-Master1.xls as MASTER.xls

ActiveWorkbook.SaveAs Filename:="C:\DATA\MASTER.xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False _
, CreateBackup:=False

' Determine how many WBs are available in C:\Data\
' Wb's must be appended into MASTER in Order - Low File Number to High

' If only ONE file in Directory, Then exit Sub
' If only TWO or More Files in Directory,
' Run AddHeading, then Run Combine_ALL
' If THREE or MORE, Run AddHeading, then Run Combine_ALL
' AND Loop Combine_ALL, as required

End Sub

Sub ADDHEADING()
' Open/Activate # 1 File and Select Row 1 ONLY (Header Row)
Workbooks.Open Filename:="C:\DATA\1.xls"
Windows("1.xls").Activate
Rows("1:1").Select
Selection.Copy
' Activate Destination File, and Insert Rows
Windows("Master.xls").Activate
Rows("1:1").Select
End Sub

Sub Combine_ALL()
' Open/Activate # 1 File and Select Used Range
' Start at Row 2 - The header row is not needed again
Workbooks.Open Filename:="C:\DATA\1.xls"
Windows("1.xls").Activate
Rows("2:2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy

' Activate Destination File, and Insert Rows
Windows("Master.xls").Activate
Range("A1").Select
Selection.End(xlDown).Offset(1, 0).Select
Selection.Insert Shift:=xlDown

' Activate #1 File and Close
Windows("1.xls").Activate
Application.DisplayAlerts = False
ActiveWindow.Close
Application.DisplayAlerts = True
End Sub

' At this point it should loop thru all available Source Files

 
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
Working with files in directory... Tom Excel Programming 1 September 7th 05 02:31 PM
Files in a directory? Greg B Excel Discussion (Misc queries) 5 May 11th 05 09:46 PM
How to determine the parent directory KS Wong[_2_] Excel Programming 5 May 6th 05 02:27 AM
Check if directory empty OR no of files in directory. Michael Beckinsale Excel Programming 2 December 4th 03 10:12 PM
How does Excel determine the TEMP directory? Miso Excel Programming 3 July 31st 03 02:19 PM


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