We help IT Professionals succeed at work.
Get Started

Use VBA to Reproduce Explorer "Copy As Path" option

PeterFrb asked
Last Modified: 2020-10-28
If I am doing a search through a number of files for a particular word ("Motor") or file configuration (".pdf"), I can, once the procedure is complete, press <Shift><Right Click>, and then left click on "Copy as Path".  That takes all the found elements and stores them to the clipboard, where I can paste them any where I want, i.e., a text file or Excel.  

I would like to replicate this functionality using VBA code.  I would like VBA to capture a whole series of folder/file paths, based on the search criteria given it.  I do know how to use vba to invoke a command prompt, and have the prompt run Explorer from a set folder:

Shell "Explorer C:\FindFiles\

Open in new window

What I don't know how to do is choose a search criteria when running Explorer, and I also don't know how to give VBA visibility to the files it has found.  What might also work is redirection (">") which produces sends command-line output elsewhere.  (i.e.,
Shell "Explorer C:\FindFiles\ > CopyAsPath.txt

Open in new window

).  (I realize that the previous example goes out on a limb, ss windows has become so dominant a part of the landscape, redirection is hardly in place any more.

Anything that will support VBA to see the results of a search is what I seek.  Thank you.
Watch Question
Distinguished Expert 2017
This problem has been solved!
Unlock 2 Answers and 10 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE