Saturday, April 20, 2013

Rename a file with VBA


Sub RenameOneFile()

'___________________________________________________________
'

'This Excel VBA macro renames the file extension on
'one existing file 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 change
'This quick macro works in Excel

'___________________________________________________________
'


Dim PreviousFileName As String
Dim NewFileName As String

 'assume cell A1 contains the filename only, without extension
 '============================================================

   PreviousFileName = "C:\Temp\" & Worksheets("Sheet1").Cells(1, 1).Value & ".txt"
   NewFileName = "C:\Temp\" & Worksheets("Sheet1").Cells(1, 1).Value & ".TXT"
     
   Name PreviousFileName As NewFileName

End Sub

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