View Single Post
  #3   Report Post  
Myrna Larson
 
Posts: n/a
Default

And, in case FileSearch doesn't work correctly (it doesn't for me in XL-XP --
returns no files when there ARE matching files), in the past I've posted code
to retrieve a list of files in a directory. So has Bill Manville. If you can't
find it on Google, I can re-post.

On Wed, 9 Feb 2005 08:28:13 -0800, "Jason Morin"
wrote:

Try this macro. Change "MyFolder" to the actual path. To
use, open up a new workbook, press ALT+F11, go to Insert
Module, and paste in the code. Press ALT+Q, go to Tools
Macro Macros and run it.


Sub ChangeXLS()
'Constructive criticism from VBA programmers appreciated
Dim MyFolder As String
Dim NewName As String
Dim OldName As String
Dim patharray As Variant
MyFolder = "C:\Program Files\ztest"
Application.ScreenUpdating = False
With Application.FileSearch
.NewSearch
.LookIn = MyFolder
.SearchSubFolders = False
.Filename = "*.txt"
.FileType = msoFileTypeAllFiles
Application.DisplayAlerts = False
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
patharray = Split(.FoundFiles(i), "\")
OldName = patharray(UBound(patharray))
NewName = Application.WorksheetFunction. _
Substitute(OldName, ".txt", ".xls")
Workbooks.Open Filename:=MyFolder _
& "\" & OldName
With ActiveWorkbook
.SaveAs Filename:=MyFolder & "\" & NewName
.Close
End With
Next
Else
MsgBox "There were no files found."
Exit Sub
End If
Application.DisplayAlerts = True
End With
Application.ScreenUpdating = True
End Sub

---
HTH
Jason
Atlanta, GA

-----Original Message-----
I have about 3000 .txt files I need to open in excel and

just save them. Is
there a way I can batch run these? It would involve

opening the txt file and
saving it as the same name.
.