VBA macro - How To Open Any File If Partial Name is Known - Office 2016, please?

Tybet

New Member
Joined
Feb 20, 2020
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Welcome All,

Dear users I have just joined as I gave up on trying „uncle google”.
I am quite advanced computer and excel user but quite poor in VBA macros.
However I am good listener / reader so please advise on following (hope simple task).

What I have:
1. I have about 40 files in folder on local drive
2. Extensions of the files are various (mostly xls , doc, pdf)
3. Each file has quite a long name but each one has a UNIQUE signs (letters ABC & digits)

Now, My problem is (what I am looking for):

1. I have ”command button” created and wish to execute task when clicked:

THAT TASK WOULD BE:

*OPEN ANY FILE THAT MATCHES UNIQUE SIGNS AS PER MY REQUEST / STATEMENT
*PRINT SUCH FILE WITH Or WITHOUT OPENING IT ( if possible ignore pop up windows from printer about margins too small etc.)

IMPORTANT: I want to create one Command Button for One Specified File only (I guess its even easier to create).

Why I dont want to use Hyperlinks: As the revisions of the files may changed from time to time but NEVER UNIQUE SIGNS.

Sorry If such thread been under discussion but trust I have been browsing internet for 4-5 days so far and couldn’t get the answer.
Some of the solutions were close but unfotunately code was not available in my 2016 office (like FileSearch)

Please help me to solve that little problem.

Tybet
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I think your best bet would be to list the possible file extensions (using VBA.Dir command and following your logic, e.g. *.doc*, etc), and then PrintOut or something along those lines.

Otherwise, you may be better off programming this thing in something like Python, and using the specific library to get to Office related APIs (e.g. *.doc*, *.xls*, etc)

Either way you have to programmatically determine the file type you're dealing with. There's no way around that. But it's fairly easy to work around the deprecation of FileSearch using native Windows Dir and related commands.
 
Upvote 0
I think your best bet would be to list the possible file extensions (using VBA.Dir command and following your logic, e.g. *.doc*, etc), and then PrintOut or something along those lines.

Otherwise, you may be better off programming this thing in something like Python, and using the specific library to get to Office related APIs (e.g. *.doc*, *.xls*, etc)

Either way you have to programmatically determine the file type you're dealing with. There's no way around that. But it's fairly easy to work around the deprecation of FileSearch using native Windows Dir and related commands.

Hi,

I appreciate your reply but honestly didn’t bring me any closer to solution. However thanks for your effort. I was able to find almost ideal solution... a code that was searching a file with UNIQUE SIGNS in filename regardless of extension...but....problem was to name it so I can call the result and e.g. Open it or Print. Anyway thanks for response.
Hope there will be somebody with clearer solution to me (as I said I am poor in VBA code). I attached screenshots that are almost ideal but...like I said how to proceed further to open that FOUND FILE?
 

Attachments

  • CCEFB53D-C55A-4C68-970D-E1671B4BCA98.jpeg
    CCEFB53D-C55A-4C68-970D-E1671B4BCA98.jpeg
    117.8 KB · Views: 16
  • 7351A219-335F-4429-8C11-89103D8D7A09.jpeg
    7351A219-335F-4429-8C11-89103D8D7A09.jpeg
    108.5 KB · Views: 16
Upvote 0

Forum statistics

Threads
1,224,821
Messages
6,181,163
Members
453,021
Latest member
Justyna P

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