ignoring part of a filename during a search

furnace

New Member
Joined
Mar 7, 2009
Messages
8
I am new to macros and programming in general.
I have a question/problem which i believe should be easy to fix, here it goes.

I have a macro written to find an .xls file in a certain directory.
the .xls file has a numerical value at the end which will change.
I am looking for a simple way to be able to get this file just by searching the content before the numerical value.
Ex:

ThePath = "C:\Temp\test\original_001.xls"

I want to be able to search "C:\Temp\test\orignal" and leave out the 001 part. (it will always be an .xls file)
Can this be done. I've tried looking up wildcards * but i dont think they exist in VB.
can someone help me.
 
Well, here's my take on this, and believe me this is in no way faulting you for anything, as you are new to programming.

The essence of what you want to do is a very common thing, whereby opening files with a wildcard, whether or not the path or file name contains a date or whatever...this whole endeavor is a very common practice.

After our heretofore 10 posts on this thread in dealing with a common issue, my experience is that somewhere along the line, at least one of 3 things is happening that have resulted in this not working:

- Your variables have gotten too complicated to follow for someone who cannot see your workbook, example, you are declaring a disproportionate 6 variables for ultimately just one workbook.

- Your explanations are not complete; example, just say what exactly is in cells A1 and B1 to help us understand what you are looking at.

- Maybe something else is happening in the workbook or on the D drive that you are unaware of which is causing the problem, example, some VBA event code or security restriction set by an IT department.

Again, none of this is faulting you, but it just seems that the code set forth so far should have, if not been exactly the right fit, offered enough of a way to get from here to there.

Keep in mind that dealing with folders and paths requires an exact match of characters, and exact means exact, so if there is a leading or trailing spacebar character in the cell, then that would lead to an error such as you are getting.

Try re-explaining and listing all the components not in variable terms but concrete "what they are" terms (drive, folder, file name, etc) and maybe that will help clear up what is going on so you can get an answer that will help.
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Thank you for your help.
I was playing with the code last night and i managed to get it to work.
Well....somewhat work. I will need to "tweak" a few things but i think i can get it.

thanks again.
 
Upvote 0

Forum statistics

Threads
1,215,463
Messages
6,124,965
Members
449,201
Latest member
Jamil ahmed

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