Link to home
Start Free TrialLog in
Avatar of annie meriam
annie meriam

asked on

Looping through all visio files in a folder

Hello,
I've been tasked with creating a module that will loop through all (single page) visio files in a folder to pull out all of the comments from each page/file. I've been using the macro in the link below to extract comments.
https://support.microsoft.com/en-us/help/898514/how-to-print-comments-that-are-inserted-by-reviewers-when-you-use-the
Does anyone have any ideas on how I can loop this code to run through all the files? Or how to create another macro that loops and will call this GetComments() function?

Thank you in advance!!
Avatar of Scott Helmers
Scott Helmers
Flag of United States of America image

The code in the attached Visio diagram will locate all Visio diagrams, both .vsd and .vsdx, in a folder you specify. As currently written, it will also find Visio files in all subfolders, however, you can change one parameter (see comments in the code) to ignore the subfolders.

You can use this code as the main routine and then add a call to your current macro to extract the comments. You will need to modify your code to accept a passed path to the current file, and you'll also need to add code to open and then close each file. If you need help with those things, just let me know.
Get-all-files-in-a-folder-and-its-su.vsd
Avatar of annie meriam
annie meriam

ASKER

Wow Scott, this is so helpful thank you!! I am a little lost on how to  modify the old macro so it works within your code. Could you help me out with that, or explain further? I really appreciate your guidance!
Is it a matter of copying and pasting the old module? Or do I call it as a function of sorts? Sorry, I'm very new to VBA!
You're on the right track... paste the old module into the same file with my code and then call it each time the code finds a Visio file.

I've attached an updated file that includes those changes. You'll notice several things:
1) I added a parameter to GetComments() so we can pass in the path+file name.
2) I added code at the beginning and end of GetComments() to open and then close the Visio file.
3) There's a bit of trivial error handling code surrounding the Open statement just in the case the file can't be opened for some reason.
4) I added indents to GetComments() to improve readability -- doesn't change the logic but makes it easier to follow.
Get-comments-from-all-files-in-a-fol.vsd
Annie -- did the code I posted work for you? If so, please close this question when you have a chance. If not, let me know how else I can help.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.