Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Run a macro on multiple files in a folder

Posted on 2012-09-20
2
Medium Priority
?
330 Views
Last Modified: 2012-09-20
I have a working macro that does stuff to a file, saves and then closes it.  The macro is saved in my PERSONAL excel file, so it can be run on any excel file. Can somebody show me another macro or some other way to execute my existing macro on every file in a folder instead of having to manually execute it for each individual file?

Something like "For each file file in MyFolder, run MyMacro"
0
Comment
Question by:dbfromnewjersey
2 Comments
 
LVL 19

Accepted Solution

by:
Ken Butters earned 2000 total points
ID: 38417904
in your VBA window ... in tools references... make sure you select "Microsoft Sripting Runtime"

You can use the object browser in vba window (Hit F2) ... select Scripting library in the dropdown to see available methods with scripting library.


Dim fso As New Scripting.FileSystemObject
Dim FileObj As File
Dim FolderObj as Folder

FolderObj = fso.GetFolder("C:\someFolder")

For Each FileObj in FolderObj.Files
  <Do something with file... by referencing FileObj>
Next

Open in new window

0
 

Author Comment

by:dbfromnewjersey
ID: 38417986
Thank you.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question