Monday, May 23, 2011

Rename Folders In Excel VBA

Hi

Suppose you want to rename folders in one go
For example snapshot below-




All you need to get list of folders with complete path and folder name in COL A and COL B and type the new names in COL C Then run the macro

Here is the code:-

Sub rename_folder()

Dim old_name, new_name As String

For i = 2 To Sheets(1).Range("a1").End(xlDown).Row

new_name = Left(Sheets(1).Cells(i, 1).Value, Len(Sheets(1).Cells(i, 1).Value) - Len(Sheets(1).Cells(i, 2).Value))

new_name = new_name & Sheets(1).Cells(i, 3).Value

old_name = Sheets(1).Cells(i, 1).Value
Name old_name As new_name

Next i

End Sub

4 comments:

  1. Here i got a error message as file not found...

    Anything i missed to follow... Please help me

    ReplyDelete
  2. Thanks for the post. How would I change the names for shortcuts to folders?

    Thanks

    ReplyDelete
  3. Hi

    I got the same error message as "File not found".

    Could you please help.

    ReplyDelete

Import data from SQL

Macro to import data from SQL using ADO connection string: Sub Import_data_from_SQL() ' Tools -> References -> Microsoft Active...