View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 10,593
Default rename files in a folder

Dim FSO As Object

Sub ProcessFiles()
Dim i As Long
Dim sFolder As String
Dim fldr As Object
Dim Folder As Object
Dim file As Object
Dim Files As Object
Dim this As Workbook
Dim cnt As Long
Dim sName As String

Set FSO = CreateObject("Scripting.FileSystemObject")

Set this = ActiveWorkbook
sFolder = "C:\MyTest"
If sFolder < "" Then
Set Folder = FSO.GetFolder(sFolder)

Set Files = Folder.Files
cnt = 1
For Each file In Files
If file.Type = "Microsoft Excel Worksheet" Then
sName = Replace(file.Name, ".xls", "")
' Name file.Path As Replace(file.Path, sname, Left(sname, 6))
cnt = cnt + 1
End If
Next file

End If ' sFolder < ""

End Sub



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Varun Nair" wrote in message
...
Hi,

I have a set of .wav files in a folder. Can some one help me with a macro
which could rename all the files in a folder.

the naming scheme should be as mentioned below

oldname : 123456_xyz
newname: 123456

i.e. the new name should only contain the first 6 first characters of the
ond name.

--
Varun Nair