Filename truncated @ underscore when removing file extension

Cyberwolf000

New Member
Joined
May 5, 2008
Messages
18
Hi all,

What I am attempting to do is to strip off the file extension of a file and then search for that file name in a list on a worksheet. Here is the line of code I thought should work

TempName = Left(FileItem.Name, Len(FileItem.Name) - InStrRev(FileItem.Name, ".") - 1)

What is appening is if there is an underscore in the filename all I get is the characters before the underscore ie.

Aero_PM.accdb would only give me Aero instead of Aero_PM. Any ideas on why this is happening?

TIA
 

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
No it isn't - it's giving you as many characters from the beginning of the filename as there are characters in the extension, minus one. If your file was called Aero_PM.mdb, it would return just Ae. You don't need to consider the length of the file name in your calculation as InStrRev returns the position of the dot from the beginning of the string, not the end.

Try this:-
Code:
TempName = Left(FileItem.Name, InStrRev(FileItem.Name, ".") - 1)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
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