SolvedPrivate

VBA to find file and if found move to parent folder

Posted on 2015-02-24
2
16 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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
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 demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

820 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