Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running a Macro to open all files in a directory

Status
Not open for further replies.

adeolt

IS-IT--Management
Sep 26, 2005
2
IE
Hi I am new to the board and I have a limited coding knowledge. I have a number of files saved to a directory that I would like to open in bulk, run a macro to convert it to a certain format then close it again saved in my format.

Is it possible to select multiple files, run this macro on them and save?

Could someone point me in the right direction please.

Hope you can help
Thanks
 
This may not be exactly what you need but it might be something you could use. In essence it is picking off all files in MyDir that are .TXT types and in this case I'm just putting the names into the current Excel column but within the IF statement you could do anything you want while the file is open.
===============================================

Sub GetNamesOfFilesInFolder()
Dim PathName As String 'Will use the Dir function to find all filename in this Path
Dim FName As Variant 'Temporarily stores all files in Pathname
PathName = "c:\MyDir\" ' (Be sure to include "\" )
FName = Dir(PathName & "*.txt") 'Set up dir and returns first file in Pathname
While (FName <> "") 'Loops until "" found
If (FName <> ".") And (FName <> "..") Then
ActiveCell.Value = Mid(FName, 1, 25)
ActiveCell.Offset(1).Select
End If
FName = Dir()
Wend
End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top