Set a folder path to rename all files instead of folder pickup method

randaubienghoc

New Member
Joined
Apr 25, 2020
Messages
19
Office Version
  1. 2016
Platform
  1. Windows
Hi everyone,

Could you please help me to revise the code in the Excel file so that I can set a folder path and then all files in the folder can be renamed?: Rename-1.7z

In the file that I obtained from the Internet, the author used the method to manually navigate a folder and select multiple files in the folder to rename. The file purpose is to rename filenames to VBA supported characters.

I preferred to using a defined folder path but I do not figure it out. I hope you guys can help me. Thank you.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Keep posted, if you have a solution. Hope some experts will see this issue & will say something on this.
 
Upvote 0
Hi @mehidy1437 solution found :D

VBA Code:
Sub Main()
On Error Resume Next
    Dim SourceFile As String, TargetFile As String
    Dim Path As String
            Path = "C:\Users\Admin\Desktop\Rename\" 'change the path
            With CreateObject("Scripting.FileSystemobject").getfolder(Path)
                For Each Fi In .Files
                    SourceFile = Fi.Path
                    TargetFile = Path & "\" & SourceToDest(Fi.Name, 1, 5)
                    LoaiDauFile SourceFile, TargetFile
                Next
            End With
End Sub
 
Upvote 0
That's great. Glad to know that you have got it.
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,293
Members
449,077
Latest member
Rkmenon

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