Search Folders & Subfolders For Files By Date Modified & Move/Copy Them

Aug 5, 2009

I'm trying to make a macro that will search a folder and move all files from 2008 into another folder. So far it can do this, but what i need is for it to search subfolders also. At this point it moves all files from the main folder, but nothing from the subfolders.

Option Explicit
' Reference site [url]

Sub Copy_and_Rename_To_New_Folder()

Dim objFSO As FileSystemObject
Dim objFolder As Folder
Dim PathExists As Boolean
Dim objFile As File
Dim SrcFolder As String
Dim DestFolder As String
Dim x, Counter As Integer, Overwrite As String, strNewFileName As String
Dim strName As String, strMid As String, strExt As String
Dim LastModYear

View 5 Replies


ADVERTISEMENT

Create Macro That Will List All Folders / Subfolders And Files In Order In Excel?

Feb 8, 2013

My problem is to create a macro that will list all folders, subfolders and files in an order in excel. So that I know which folders and files belong to which main folder, more like a hierarchy.

For example,
Sourcefolder
Subfolder 1
File1

I have code that list all files in folders and subfolders, but it does not put them in a hierarchy fashion.

View 8 Replies View Related

Use Excel VBA To Copy Multiple Files From Different Source Folders To Different Folders?

Jun 12, 2014

I need to back up files, which may be excel or MSword, by copying them from different directories, say C: to the backup directory, say X:. any vba to backup the files? I expect the vba can copy all file listed in column A.

E.g. C: est1File1.xls or C: est2File2.doc, and then pasted to the directory in column B. e.g. X:BackupFolder1 or X:BackupFolder2.

View 1 Replies View Related

Move Files To Dynamic Folders Based On Cell Value

May 13, 2007

I am not so sure this can be done through a macro, but here is what I want.

I have a folder with say around 1000 excel workbooks. I need a macro to

1. Open each file in the directory specified
2. Read the contents of a particular cell, for ex, A1
3. Create a folder in the same directory with the value of A1
4. And, move the excel workbook itself to that folder.

5. Then it opens the next file
6. If the value of A1 is the same as that in the first workbook, it simply moves it to the already created folder, else it creates another folder with the new value of A1 and moves it there.

Hope I am not too confusing. Searching the forums does not give me an exact picture of how it can be done.

Note: I would also like an option where when I execute the macro, it should pop up with an option to select the folder in which the files are, since the files are not always saved in a static file path.

View 6 Replies View Related

Search Folders And Create Hyperlinks To Files

Feb 18, 2009

I have a list of file names sans extension in column A. I want to search a folder I specify and if file is found create a hyperlink to said file either in a new cell or in column A.

The code I have does the search fine, but its hyperlinking is offset and I can’t get it to match the link to the file name.

Also it breaks if it can not find the file.

Here is the code...

View 9 Replies View Related

Copy And Rename Files In VBA By Searching Multiple Folders For Files?

Jan 4, 2014

how I can loop through folders to select files starting with a certain word and copy all of them to a different folder and rename them. The folder structure is given below

Company 1(parent folder)
North South East(sub folder) West(sub folder)
Jan Feb Mar.... Dec Jan Feb Mar.... Dec Jan Feb Mar.... Dec Jan Feb Mar.... Dec

In the above structure, the files are present inside each folders Jan, feb...Dec under the regions North, South East n west. note that I have to select files starting with "Sales" and copy them into a new folder(say results) and rename copied files as Sales1.xls, Sales2.xls etc. (Files are not present in the folder company1, north, south, east and east.)

View 1 Replies View Related

Time For Getting Data - Search For 445 Files In Folders On Specific Path

Jan 1, 2013

I build a VBA that search for 445 files in folders on specific path.

The code opens each file, take each time the same 31 rows, filter them and paste in the main data base file and then close the origin file.

So, for 445 files it takes about 6:30 minutes.

View 4 Replies View Related

Dir Folders And Subfolders Macro Writes Over It Self

Sep 14, 2009

I have a code that will write all filenames in a selected folder and all subfolders in a list. The problem is that when i open a folder with about 5000 files in only 187 are visible in the list. You could see that the program writes all filenames but it writes everyting in the first 187 columns over and over again. Here is the

View 5 Replies View Related

List Folders & Subfolders From Directory

May 20, 2007

how to list all the folders/subfolders (no files) of a specified directory?

I've seen a few examples of listing filenames from directories but I'm unsure how to just list folders/subfolders.

View 6 Replies View Related

List All Files In Directory Modified After Certain Date

Sep 5, 2012

I wish to create a macro that looks in a specific directory "D:Records" . It finds the files which are modified after a date "January 01, 2012" in this directory (pdf files). Then it imports these files names into a worksheet.

View 8 Replies View Related

List Files In Directory With Date Modified

Nov 28, 2006

I currently have a macro working where I can populate the A Column with files from a directory and based on its file extension, however I am having problems trying to populate the second (B) column with that files date modified. I have searched the forum to no avail and I must admit I not the best with vba.

Sub INP_files()
' searches within the file location
' C:Arenium_Projects31-1853012_Barnawartha BOSCADDMX
Dim rngOut As Range
Dim strPath As String
Dim strfile As String
' Sheets("INI_FILES").Select

View 3 Replies View Related

Excel 2007 :: Sort All XLS Files In Folder By Modified Date?

Jul 24, 2012

I'm trying to sort all .xls files in a folder by modified date. I want most recent at top because then I will be cycling through and using the most recent version of files that have similar names.

Excel 2007.

The code I have so far is this:

Code:
Sub autolink()
Dim folderPath As String
Dim FileName As String
Dim wb As Workbook

[Code]....

But I need something before it sort the folder by the modified (or better creation date) because there are several files with similar names. I know know, I could put a date in the file name and look for that but I don't control the naming of the files.

View 7 Replies View Related

Create Folders & Copy Files To It

Jun 26, 2007

I need to create a macro that will allow the user to create a directory based on a template directory, with all directory paths/ names stored in workbook cells:

1) Create a new directory (name/path specified in workbook)
2) Go to a template directory & copy the entire directory, subdirectories & all files
3) Paste them into the new directory
4) Save a copy of the workbook into the specified location from (3)

Example:
X:Templates
-copy all to-
X:Projects(Value specified in workbook cell)

View 3 Replies View Related

Consolidate Data From Multiple Files Within Folders & Sub Folders

Aug 16, 2009

I have managed to get this far - I have put together a macro (from different threads on this site) that opens closed workbooks, copies data in one of the sheets (same sheet in each of 28 books), and pastes the data it into a master book sheet, each paste starting below the last. So that bit is working. The first bit of help I need is a line of code that will make the macro loop through a number of sub folders in a main folder. My code at the moment works as long as I specify a path that ends with the name of one subfolder, and it only loops through this subfolder. I would like the path to end at the folder that holds all the subfolders ('Workbooks' in the path below), and then add some code that tells it to apply the macro to all subfolders in this folder, so it loops through them all.

The second issue is that after the macro goes to the closed book(s), copies the data in there and pastes it into the master sheet (into columns E:FG), I then need it to go back to the workbook it just copied from, go the same sheet, to three specific cells on that sheet (FH1:FH3), copy the content, go back to the master sheet, and now repeatedly paste the content (values only and transposed) of these three cells into three cells (in columns B:D, with row number being dependent on what rows the first lot of data was copied into) next to every row it just previously pasted in for me. When it loops to the next workbook, it needs to do the same, and the three cells will have different content than the ones in the previous workbook paste.

I dont know how to define the range it needs to paste into the second time. I tried using the definition I used for the first paste (MCDrow), to tell it that it is the same rows, just different columns, but this is not working.

Here is what I have so far, which does the first part of what I need, except for needing a way to have it loop through all subfolder in the 'Workbooks' folder (at the moment it lists Barwon South West as a subfolder in that path, but I actually have multiple subfolders, not all called Barwon South (all different names) that it needs to loop through and do both the first and the second paste for. I have taken out the code I was trying to use to do the second paste, as this was not working and the code is pretty messy as it is (I sort of bumble along, being so new, and I know the code is not very clean or efficient!).

Can someone help me put in the few lines I need to loop through all my subfolders (if you give me an example I can probably extrapolate), but to get you started, three of the subfolders are Barwon South West, Eastern Region and Gippsland. And can someone help me put in the code that will do the second paste for each workbook?

Sub Click2()

Application. ScreenUpdating = True
Dim MCDrow As Long
'Dim SubFolders As String
MCDrow = ThisWorkbook.Sheets("Client Data").Range("A65536").End(xlUp).Row

Fpath = "Q:Clinical ServicesCS Statewide DatabaseWorkbooksBarwon South West" ' change to your directory
'SubFolders = True
Fname = Dir(Fpath & "*.xls")
Do While Fname <> ""

ThisWorkbook.Sheets("Client Data").Unprotect

Workbooks.Open Fpath & Fname
Worksheets("Client Data").Activate
Worksheets("Client Data").Unprotect

View 6 Replies View Related

Search Folders And Sub Folders For Worksheet And Return Range?

Jul 8, 2013

macro and I think this has me on my way; however, I do not understand the code and I am having difficulty modifying it. It returns the path in cell $A1 of my workbook, but I get reference errors in $B1:$L1.

I would like for the code to start entering the values in row 2 of my current worksheet. Row 1 I want to make a header row. The first column I like having the file path. Can the path be changed to a hyperlink? I would then like for it to return the values in $AP1:$BC1 to $B1:$O1 of my current workbook.

View 4 Replies View Related

Excel 2010 :: Rename Files In Multiple Folders And Copy To New Folder

Sep 22, 2013

For the last year I have been downloading cash register X1 and Z1 files onto an SD card. Each night's files (X1 & Z1) are stored in a new folder with the naming convention "RP + [DATE]", (EX: RP120910, [YYMMDD]). I have 265 folders! I need to go through each folder, select the Z1 file (I don't care about the X1, X2 or Z2 files) and rename each with the following naming convention: "Z1 + folder_name + .xls". For Example: Folder RP120910 contains the Z1 file named "Z1_T1729.ECR". After renaming, the file should be "Z1RP120910.xls". As the VBA code loops through each subfolder, selecting and renaming the Z1 files, I would like the new files to be placed into a new folder named "Z1Files". Note: All subfolders are currently in a directory named "RegisterFiles". I am using Excel 2010.

View 3 Replies View Related

A Way To Querry,(x).Xls Files In (x)subfolders

Dec 17, 2008

Need to querry various .xls files for various data values in column A.

The directories will stay static, subfolders will be dynamic. Is there a way to querry through the ever varying subfolders and search for BOM.xls / BOM2.xls files? Searching Column A?

View 14 Replies View Related

Getting List Of Files In A Folder And SubFolders?

May 9, 2013

I have a problem with getting the list of files in subfolders. this code is writing the names of files in a folder to column "A". But it is just "target" folder. But i need to get the name of all files not just under the target folder but also subfolders of target and even subfolders of subfolders of target

VB:
Dim FSO As Object
Dim SourceFolder As Object
Dim FileItem As Object [code]....

View 9 Replies View Related

List Subfolders And Count Files

Apr 22, 2012

I am looking for a macro that will list all subfolders (all levels) within a directory and count files in each of those subfolders. No file names, just number of files contained in each folder.

View 9 Replies View Related

Opening CSV Files From A Folder And All Its Subfolders

Apr 25, 2013

I tried to search for threads about opening files from multiple subfolders but the following codes does not open files. Could someone please check and edit the code that I have below:

Dim lCount As Long
Dim wbResults As Workbook
Dim wbCodeBook As Workbook

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False

On Error Resume Next

[Code] ........

View 7 Replies View Related

File Listing Of All Files Including Subfolders

Aug 4, 2003

Is there a way using VBA to list all the files contained in a particular folder which automatically reads through the subfolders of that folder?

The subfolder names should not appear anywhere except in the path of the file name.

The file names have to be in the form of full path including file name with extension.

View 9 Replies View Related

Browse For Folder / Index Files And Subfolders?

May 12, 2014

I found some code that works well to index a folder and all sub-folders for file names.

The issue is that the folder used is coded in an excel spreadsheet (cell C7) in the below code and whether to look in sub-folders (cell C8 - True or False).

Code:
Sub ListFiles()
iRow = 11
Call ListMyFiles(Range("C7"), Range("C8"))

[Code]....

I have tried to incorporate the browse for folder and select if sub-folders are used, but it isn't working.

View 1 Replies View Related

Search Folder And Subfolders, Open Workbook Macro

Jun 5, 2009

i am trying to open a get a code working that will enable me to enter a file name in a cell of the current workbook open, then search through a root directory and subfolders, find the file and open it. the code below i giving me grief. i am using 2007 excel.

With Application.FindFile
.NewSearch
.LookIn = "J:IsolationDataBaseIsolationProcedures"
.SearchSubFolders = True
.Filename = Range("N2").Value
.MatchTextExactly = True

View 9 Replies View Related

List All Changed Excel Files Today On Drive And Hyperlink (Including Subfolders)

Aug 9, 2014

provide some code which lists all today changed Excel files on the C drive and hyperlink them.

View 3 Replies View Related

Excel 2003 :: Copy And Move Files To Create Backups For 7 Or 8 Years

Aug 30, 2012

Using Excel Office 2003.

I have been using VBA to copy and move files to create backups for 7 or 8 years now, and it works great. However, recently I have been working on a way to use SD cards for the backups and the FileCopy command is much slower than using Windows Explorer.

I am looking for some alternate command lines that might do the job faster. I would like to know what Explorer is using.

View 8 Replies View Related

Search For Files, Copy & Paste In Another Folder

Jun 29, 2006

I want to search for some text in a file. If found, I want to copy that file into another folder. I'm using the code below to do half the job.

Sub test()
With Application.FileSearch
.NewSearch
.LookIn = "C:Documents and SettingscDesktop1"
.SearchSubFolders = True
.Filename = "*.htm"
.TextOrProperty = "Status Rekod"
.MatchAllWordForms = True
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then
For I = 1 To .FoundFiles.Count
'I want to use the FileCopy function here to copy the found files to
'C:Documents and SettingscDesktop est. How do I do this?
Next I
Else
MsgBox "There were no files found."
End If
End With
End Sub

View 9 Replies View Related

Files Within Sub Folders

May 29, 2007

I am using the code below to list all files within a specific folder however I need to know about ALL the files within the underlying sub folders (of which there are many).

I have tried wildcards when declaring the folder but it does not work.

Sub List_Files()

Dim fsoObj As Object 'Scripting.FileSystemObject
Dim fsoMapp As Object 'Scripting.Folder
Dim fsoFil As Object 'Scripting.File
Dim sFolder As String
Dim i As Long
Dim filtype As String
sFolder = "V:T-ASSETAsset ScotlandNetwork Capacity Section1 Business Plan"

Set fsoObj = CreateObject("Scripting.FileSystemObject")

'Set fsoObj = New Scripting.FileSystemObject........................

View 9 Replies View Related

VBA Saving PDF Files Into Folders

Sep 29, 2013

I have this code that generates excel pages as pdf files, but I can't get it to save it in its individual folders. For example, I have the sheet name as Brian Lin, I want to save the pdf into the folder called Brian Lin, then if I have the sheet name as Lilly Tran, the pdf should save into the folder called Lilly Tran. Here's my code. The code is one step short of what I want it to do, it saves in the folder right before the name folders.

Code:

Sub Macro1()
Dim wsh As Worksheet, vWshs
Dim sFolderName As String, set_Path As String, name As String, hwas As String, sname As String, swsname As String
vWshs = Array("Rates", "Inputs")
set_Path = "C:UsersJonathanDesktopFaFundInvoices" & hwas & ""

[Code]...

View 4 Replies View Related

Finding Files In Folders

Jun 12, 2008

I need to design code that can check to make sure a specific file is found before it executes.

Our files are all going to start with the same words followed by the date

ex. Name 10-2-1998

I want the code to be dynamic and be able to check in the folder that the current excel sheet is in for the file i need and then have it ready for use in my macro.

View 9 Replies View Related

List Files And Folders

Jun 19, 2008

I have a folder that has a bunch of other folders in it, each containing many files. Is there an easy way to get a file directory into excel, so that I now would have a spreadsheet that tells me what all the folders are and what files are in each one?

short example: main folder = mystuff
subfolder1 = my pix, contains pic1 and pic2
subfolder2 = otherstuff, contains otherstuff1 and otherstuff2

Can excel find these things and give me a list indicating that the 'mystuff' folder contains these two folders, and also list the two files under each folder?

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved