SolvedPrivate

VBA to find file and if found move to parent folder

Posted on 2015-02-24
2
13 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
2 Comments
 
LVL 35

Accepted Solution

by:
Kimputer earned 500 total points
Comment Utility
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 5

Author Closing Comment

by:Flora
Comment Utility
Thanks very much
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This is an Add-On procedure to be used in conjunction with the code provided in Reducing EE Email Clutter using Outlook (http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/A_3146-Outlook-Processing-EE-emails-on-Receive.…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now