ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   opening each file in a folder (https://www.excelbanter.com/excel-programming/336045-opening-each-file-folder.html)

JT

opening each file in a folder
 
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

Tom Ogilvy

opening each file in a folder
 
Look in Excel VBA help at the DIR function. The sample code provided there
should get you started.

--

Regards,
Tom Ogilvy

"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




Ron de Bruin

opening each file in a folder
 
See the examples on my site

http://www.rondebruin.nl/copy3.htm

Or
http://www.rondebruin.nl/copy4.htm

--
Regards Ron de Bruin
http://www.rondebruin.nl


"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




Bob Phillips[_6_]

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





All times are GMT +1. The time now is 09:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com