SolvedPrivate

VBA to find file and if found move to parent folder

Posted on 2015-02-24
2
18 Views
Last Modified: 2016-02-10
Hello,

i have like 200 folders with different names which are inside a Master Folder.

i want VBA code that looks inside each of these 200 subfolders and search for any file with format .epub and if found then move it to the Master folder.

thanks.
0
Comment
Question by:Flora
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 36

Accepted Solution

by:
Kimputer earned 500 total points
ID: 40628187
If only one level of subfolders, this is it:

Sub browsefolders()

master = "c:\temp1\"

Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(master)

For Each subfld In fld.SUBFOLDERS

    For Each foundfile In subfld.Files
    
        If LCase(Right(foundfile.Name, 5)) = ".epub" Then
            fso.movefile foundfile, master
        End If
 
    Next

Next


End Sub

Open in new window

0
 
LVL 6

Author Closing Comment

by:Flora
ID: 40628312
Thanks very much
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
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…

688 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