Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
SolvedPrivate

VBA to find file and if found move to parent folder

Posted on 2015-02-24
2
Medium Priority
?
20 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
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‚Ķ

610 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