Useful VBA Macros for Excel and Word
A compendium of some of my old VBA macros from the most annoying and simple ones to those that defy you at the end of a long day. I had to build the macros to deal with the demands of my job to manipulate strings, cells and files and this blog is a way to sort the most useful macros scattered all over my disks. I am not a professional programmer though, so I will accept absolutely no liability for any damage!
Saturday, April 20, 2013
Rename several files with VBA
Sub RenameSeveralFiles()
'___________________________________________________________
'
'This Excel VBA macro will rename the file extension on
'several existing files on your hard disc
'You can modify it to suit other changes in filenames
'Be careful, this is very powerful and it will not
'stop to ask you to confirm the filename changes
'This quick macro works in Excel
'___________________________________________________________
'
Dim PreviousFileName, NewFileName As String
Dim i As Long
'assume column A contains the filename without the extension
'from row 1 to row 3.
'==========================================================
For i = 1 To 3 'Here, change the values of i to
'suit your starting row and ending row
PreviousFileName = "C:\Temp\" & Worksheets("Sheet1").Cells(i, 1).Value & ".TXT"
NewFileName = "C:\Temp\" & Worksheets("Sheet1").Cells(i, 1).Value & ".txt"
Name PreviousFileName As NewFileName
Next i
End Sub
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
You may comment or show me other VBA tricks, but don't rest assured I'll always reply because I only have 24 hours in a day's hard work, and only a few minutes a week to update this blog... I'll try my best though...