Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Copy range of many files in directory.

Hi,

I have a lot of files in a directory (numbers vary over time). I want
to copy the same range in each of the files to a new file.

How do I do that?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy range of many files in directory.

Use the following code:
Sub readingFiles()
On Error Resume Next
Dim fs As FileSearch
Dim fileStr As String, wb As Workbook, wbNew As
Workbook
Dim r As Long
Set wbNew = Workbooks.Add ' you can use your own
workbook to copy the ranges
Set fs = Application.FileSearch
fs.LookIn = "C:\YourPath" ' You need to set files path
fs.NewSearch
fs.FileType = msoFileTypeExcelWorkbooks
If fs.Execute(SortBy:=msoSortByFileName,
SortOrder:=msoSortOrderAscending) 0 Then
For i = 1 To fs.FoundFiles.Count
Set wb = Workbooks.Open(fs.FoundFiles(i))
' next you can set the sheet and range you need
wb.Sheets("Rep").Range("A1:D20").Copy
' next you can use the sheet you need
r = wbNew.Sheets("Sheet1").Cells.SpecialCells
(xlLastCell).Row
' next you can use the column you want
wbNew.Activate
wbNew.Sheets("Sheet1").Cells(r + 1, 1).Select
Application.DisplayAlerts = False
wbNew.Sheets("Sheet1").Paste
Application.CutCopyMode = False
wb.Close False
Next i
End If
End Sub


Hope this can be useful

Francisco Mariscal

fcomariscal at hotmail dot com

-----Original Message-----
Hi,

I have a lot of files in a directory (numbers vary over

time). I want
to copy the same range in each of the files to a new file.

How do I do that?
.

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
open all files in directory davethewelder Excel Discussion (Misc queries) 2 August 26th 08 02:01 PM
temporary directory files IMJQT Excel Discussion (Misc queries) 1 April 9th 08 12:30 AM
Open files in the same directory houghi Excel Discussion (Misc queries) 2 May 21st 07 03:56 PM
Macro to copy range from Excel files in folder nc Excel Discussion (Misc queries) 1 June 15th 05 11:11 AM
Files in a directory? Greg B Excel Discussion (Misc queries) 5 May 11th 05 09:46 PM


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