ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need help (https://www.excelbanter.com/excel-programming/355066-need-help.html)

Michael Wise[_30_]

Need help
 

Very well could be putting this in the wrong forum but it's the only
place I could think of that I could possibly get help.

I need to rename a large selection of files in a directory. In
particular I need to remove the first 3-4 characters of the current
file name. For instance is the file name is 3410-Lime Light.cdg I need
it to be Lime Light.cdg. Can I do this with VB or am I needing to
really needing to look else where for a solution.

Thank you,
Michael


--
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


kounoike[_2_]

Need help
 
Hi

one question.
the number of removing characters is constant or vary with file names.
in later case, what is the rule to define the number of removing
characters?

keizi

"Michael Wise"
wrote in
message
news:Michael.Wise.2442xa_1141419002.8968@excelforu m-nospam.com...

Very well could be putting this in the wrong forum but it's the only
place I could think of that I could possibly get help.

I need to rename a large selection of files in a directory. In
particular I need to remove the first 3-4 characters of the current
file name. For instance is the file name is 3410-Lime Light.cdg I need
it to be Lime Light.cdg. Can I do this with VB or am I needing to
really needing to look else where for a solution.

Thank you,
Michael


--
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



Michael Wise[_31_]

Need help
 

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


kounoike[_2_]

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




All times are GMT +1. The time now is 03:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com