LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
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


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"