?
SolvedPrivate

VBA to find file and if found move to parent folder

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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

770 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