The existing filenames are too long.

  • Thread starter Thread starter fitful_thought
  • Start date Start date
F

fitful_thought

Hi,

Is it possible to rename all the files in a folder with the first twelve
characters of the existing filename?

Ta,

DL
 
Here is a sub that will rename a file. In this case it is actually moving it
on your HD.
Sub movefile()
OldName = "C:\personal\1065.xls"
NewName = "C:\a\1065.xls"
Name OldName As NewName
End Sub

So, this should do what you want. Change Myfolder to suit. Test as is then
change the ' comment lines

Sub RenameFiles()
Application.ScreenUpdating = False
Dim FN As String ' For File Name
Dim MyFolder As String
MyFolder = "c:\a\*.xls"
FN = Dir(MyFolder)
Do Until FN = ""
If FN <> "PERSONAL.XLS" Then
MsgBox """" & Left(MyFolder, Len(MyFolder) - 5) & FN & """"
'oldname="""" & Left(MyFolder, Len(MyFolder) - 5) & FN & """"
MsgBox """" & Left(MyFolder, Len(MyFolder) - 5) & Left(FN, 12) & ".xls"""
'newname="""" & Left(MyFolder, Len(MyFolder) - 5) & left(fn,12) & ".xls"""
'Name OldName As NewName
End If
FN = Dir
Loop
Application.ScreenUpdating = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top