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

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,318
Office Version
  1. 365
Platform
  1. Windows
How about this:

MyFileName = "Jan 27 MOCAS.xls"

posMOCAS = InStr(MyFileName, " MOCAS")

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

npacker

Board Regular
Joined
Oct 14, 2004
Messages
132
Is that "6" the number of characters that are being stripped?
Thanks,
Nate
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,318
Office Version
  1. 365
Platform
  1. Windows
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>
 

npacker

Board Regular
Joined
Oct 14, 2004
Messages
132
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
 

Forum statistics

Threads
1,148,269
Messages
5,745,781
Members
423,972
Latest member
franklins

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
Top