Open a file with a partial Name macro

Mhaggerty

New Member
Joined
Aug 8, 2011
Messages
4
I'm having an issue, years ago I wrote very long and detailed macros that extract information from reports generated from a management software. The macros were written for specific file names. Now the program has changed the way it names reports by adding number sequences in the report name which change each time teh report is pulled. I do not have the time to manually rename each file for the macro as there are more than 90 files: can anyone show me how to find these files with a partial file name, open and rename with the example file path and name below:

file path:
"C:\Macro\Calculator\Pending Activity 60 days\

File name to find:
Cedar Terrace-1240578-Monthly Transaction Summary-2796244_6430169.xls

I would need to open and rename this file as simply Cedar Terrace.xls

Thank you for any help you can give me...I've put a lot of hours into creating macros and this reporting enhancement has stopped me in my tracks.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
This renames the file in "C:\Macro\Calculator\Pending Activity 60 days\" that starts with the name "Cedar Terrace" as "Cedar Terras.xls". It doesn't open the file though. It just renames the file. Is that what you want?

Code:
Sub Rename_File()

    Dim strFile As String
    
    ChDrive "C"
    ChDir "C:\Macro\Calculator\Pending Activity 60 days\"
    strFile = "Cedar Terrace*.xls"
    If Len(Dir(strFile)) Then
        Name Dir(strFile) As "Cedar Terrace.xls"
        MsgBox "Done."
    Else
        MsgBox "Couldn't find a file named ""Cedar Terrace*.xls"""
    End If
    
End Sub
 
Upvote 0
Thank you so much! You've saved me hours. I was really in the weeds with complicated code and wasn't getting anywhere. Finally posted on the board and so glad I did.
 
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,225
Members
452,896
Latest member
IGT

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