Removing an apostrophy ' from the front of filename

whatzzup

New Member
Joined
Jan 11, 2011
Messages
7
I have over 200 excel files that has a apostrophy infron of the file name and wanted to remove them, the filename is currently like this '4123 Flooring, '1211 Window etc., and i want them to be 4123 Flooring and 1211 Window respectively, is there a way to change them in a simple way without doint it one at a time?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try;
Code:
Public Sub RenameFile()
    Const strPath As String = "C:\Test\"
    Dim strFileName As String
 
    strFileName = Dir$(strPath)
 
    Do While Len(strFileName) > 0
        If strFileName Like "*'*" Then
            Name strPath & strFileName As strPath & Replace$(strFileName, "'", "")
        End If
        strFileName = Dir$
    Loop
End Sub

Change the directory path to the path that the files are in.
 
Upvote 0
How is this done at a folder level? Meaning all the files are in one folder, does this mean i need to open them individually and run this macro?
 
Upvote 0
Copy the code to a standard module in a new workbook.
Change this line to point to the folder path with all the files.
Code:
Const strPath As String = "C:\Test\"
Hit the run button. All filenames should be changed. No need to open them. In fact, none of them should be open at all.
 
Upvote 0
his is how i wrote it:

Public Sub RenameFile()
Const strPath As String = "C:\'4001 Book2.xls\"
Dim strFileName As String

strFileName = Dir$(strPath)

Do While Len(strFileName) > 0
If strFileName Like "*'*" Then
Name strPath & strFileName As strPath & Replace$(strFileName, "'", "")
End If
strFileName = Dir$
Loop
End Sub
 
Upvote 0
I think Jon is asking what is the path name of the folder only (not the name of the file).

If the file you wanted updated is called:
Rich (BB code):
'4001 Book2.xls
And it is located in:
Rich (BB code):
C:\
Then your code would be:
Rich (BB code):
Public Sub RenameFile()
    Const strPath As String = "C:\"
    Dim strFileName As String
 
    strFileName = Dir$(strPath)
 
    Do While Len(strFileName) > 0
        If strFileName Like "*'*" Then
            Name strPath & strFileName As strPath & Replace$(strFileName, "'", "")
        End If
        strFileName = Dir$
    Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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