Rename the Excel Files using VBA Code

kushaldwivedi

New Member
Joined
Feb 16, 2015
Messages
2
Hi,

I have more than 1000 excel files in a single folder and there are many folders like this.

I need to write the code through which I can rename all the excel files of a Singhle folder can be renamed with the text present at "H2" in each excel file.

Pls help me regarding the same.


Regards,
Kushal Dwivedi
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi

See if this example helps:

Code:
Sub Kushal()
Dim ext$, dn$
' assumes new name always on Sheet1, without a file extension
' does not open the files
dn = "c:\pub"                                   ' the folder
ChDir dn
ext = Dir("*.xls?")
Do While ext <> ""
    Range("c21").FormulaR1C1 = _
    "=if('" & dn & "\[" & ext & "]Sheet1'!r2c8="""",na(),'" & dn & "\[" & ext & "]Sheet1'!r2c8)"
    If Not IsError(Range("c21")) Then _
    Name dn & "\" & ext As dn & "\" & Range("c21") & "." & Split(ext, ".")(1)
    ext = Dir
Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,212,927
Messages
6,110,731
Members
448,294
Latest member
jmjmjmjmjmjm

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top