Strip part of file name?

npacker

Board Regular
Joined
Oct 14, 2004
Messages
132
Good morning everyone.
I have a document named "Jan 27 MOCAS.xls". (the Jan 27 is replaced with the current date of whatever day the document is created.) I have some code that I would like to have look in the same folder this document is located, and then find the file in there that has the same name, except without the MOCAS. In otherwords, there is a file called Jan 27.xls in that same folder, and I want the code to go find that file.

I can't set the code to just always look for Jan 27.xls, because depending on the day the file was created, it will be different. If there is some way to define a variable that is equal to "Jan 27 MOCAS.xls" and just strip off the *space*MOCAS off of it, that would be ideal. Any ideas?
Thanks,
Nate
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
How about this:

MyFileName = "Jan 27 MOCAS.xls"

posMOCAS = InStr(MyFileName, " MOCAS")

MyOtherFileName = Left(MyFileName, posMOCAS - 1) & Mid(MyFileName, posMOCAS + 6)
 
Upvote 0
Nate

The 6 is the number of characters in the string " MOCAS".

Including the space.

Are you having a problem with the code I posted>
 
Upvote 0
Thanks, no, I wasn't having any problems with the code, in fact I am using it, but I was just curious what the number was so that I could use it in other areas. I just wanted to make sure I understood it fully. It works great by the way. My boss is very pleased with the spreadsheet I made!
Thanks,
Nate
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,213
Members
448,554
Latest member
Gleisner2

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