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

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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