View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default opening each file in a folder

Here's an earlier post of my which seems similar (the same). Post back if
you need more help


------------------------------*--------------------------


This code uses the FileSystemObject to loop through all files in a
directory, seek out Excel worksheets, and opens them, copies A1:A3 on the
first sheet to column A, then moves on.


You will need to adapt to whatever ranges you want to use.


Sub OpenFiles()
Dim objFSO As Object
Dim objFolder As Object
Dim objSubfolder As Object
Dim objFile As Object
Dim iRow As Long

iRow = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("c:\myTest")
For Each objFile In objFolder.Files
If objFile.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=objFolder.Path & "\" & objFile.Name
ActiveWorkbook.Worksheets(1).Range("A1:A3").Copy _
Destination:=ThisWorkbook.Worksheets(1).Cells(iRow , 1)
ActiveWorkbook.Close
iRow = iRow + 3
End If
Next

End Sub



--

HTH

RP
(remove nothere from the email address if mailing direct)


"JT" wrote in message
...
I'm having trouble getting started on a macro. I want to go to a specific
folder and open each file with an ".XLS" extension in that folder. Can

that
be done?

If so, I would appreciate any help in getting started with this code.

Thanks
for the help.
--
JT