Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Change names of files in a folder to match names in Excel Column

Mark,

Try this little macro.

Put the existing names in one column, the new names in the next column.
Don't put file extensions.

Sub RenameMyData()
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object
Dim c As Range
Dim sOld As String, sNew As String, sExt As String

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("c:\MyTest\")
For Each oFile In oFolder.Files
sOld = Left(oFile.Name, InStr(1, oFile.Name, ".") - 1)
sExt = Right(oFile.Name, Len(oFile.Name) - InStr(1, oFile.Name,
"."))
On Error Resume Next
Set c = Cells.Find(what:=sOld, LookIn:=xlValues)
On Error GoTo 0
If Not c Is Nothing Then
oFile.Name = c.Offset(0, 1).Value & "." & sExt
End If
Next
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"saybut " wrote in message
...
Hi,

I currently have a folder of word documents which have generic names
i.e. 040201-1126.doc, 040201-1127.doc and so on, but I need to change
the files names to match those on our system.

In column a in excel I have a list of the current file names and in
column b I have a corresponding list of what I need the file names
changed too. So from 040201-1126.doc need changed to OHEC1100.doc etc.

I have good experience with Excel, but not so much with VB. I can write
short macros, and have discovered a lot by recording a new macro for
various events and looking at the code. At the moment thought I can't
really deal with files and file names.

Any help would be greatly appreciated as it will save me lots of time
this way rather than editing the file names manually as we have 40 or
so new files coming out each week.

Regards,

Mark P


---
Message posted from http://www.ExcelForum.com/



Reply
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you change Excel column names from ABC to 123? joe92251 Excel Discussion (Misc queries) 4 May 9th 23 03:41 AM
How do you change the column names in Excel? flutterfly Excel Discussion (Misc queries) 1 May 20th 05 09:56 PM
How do you change the column names,in Excel? flutterfly Charts and Charting in Excel 2 May 14th 05 12:34 PM
create a list of worksheet names (from a single folder, or open files) Drew Excel Discussion (Misc queries) 2 April 15th 05 04:58 PM
how can I change the a,b,c, column headers in excel to names espray Excel Discussion (Misc queries) 1 January 13th 05 02:01 AM


All times are GMT +1. The time now is 05:51 AM.

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"