Thread: Need help
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
kounoike[_2_] kounoike[_2_] is offline
external usenet poster
 
Posts: 126
Default Need help

Then check if this one will work or not in your case.
run the macro, then select all files you want to rename.

Sub renametest()
Dim filename, flname
Dim fs, f
Const cutlen = 6 'number of removing char + 1

On Error GoTo ErrorCheck
filename = Application.GetOpenFilename _
(FileFilter:="all file(*.*),*.*", MultiSelect:=True)
If VarType(filename) = vbBoolean Then
Exit Sub
End If

Application.ScreenUpdating = False
Application.EnableEvents = False

Set fs = CreateObject("Scripting.FileSystemObject")

For Each flname In filename
Set f = fs.GetFile(flname)
flname = Mid(flname, _
InStrRev(flname, Application.PathSeparator) + 1)
If InStr(flname, ".") cutlen Or _
(InStr(flname, ".") = 0 _
And Len(flname) cutlen - 1) Then
f.Name = Mid(flname, cutlen)
End If
Next
Application.StatusBar = False
Application.EnableEvents = True
Application.ScreenUpdating = True
Exit Sub
ErrorCheck:
Application.StatusBar = False
Application.EnableEvents = True
Application.ScreenUpdating = True
If Err.Number = 58 Then
MsgBox "already same file name exist."
Else
MsgBox "error occured in the code."
End If
Resume Next
End Sub

keizi

"Michael Wise"
wrote in
message
news:Michael.Wise.2491uy_1141650906.7158@excelforu m-nospam.com...

The characters are a constant. 5 characters at the begining of each

file
name.


--
Michael Wise
----------------------------------------------------------------------

--
Michael Wise's Profile:

http://www.excelforum.com/member.php...fo&userid=6998
View this thread:

http://www.excelforum.com/showthread...hreadid=518865