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
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.
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
I am attempting to create a macro that will create a new folder on the network drive Arie:quotes that will create the new folder and save the the file in the new folder. I need the name of the file and folder to be set to the master (worksheet) cell "B3". and then if possible have it be conditional that if cell "B40" on the same master (worksheet) has a value to have the value added at the end of the filename via hyphen. This workbook has numerous worksheets in it approx 15 worksheets. I am not sure if this is relevant.
As an brief example.
Cell "B3" on the master(worksheet) contains a job name I-40 bridge So initially I would like the Folder name and file name to be I-40 Bridge
However once the Cell "B40" has been filled in with the value 54213 then I would like the file to renamed to I-40 Bridge-54213 and saved within the same folder.
I am currently working with Excel 2007 Pro edition on windows 8. I
I have found several other macro's that work with an auto save but i am unsure of how to change the directory to the network drive and show the correct file paths. This is the example of the macro I am currently working with.
Public Sub SaveAsA1() ThisFile = Range("B3").ValueMkDir "C:NewFolder"ChDir "C:NewFolder"ActiveWorkbook.SaveAs Filename:=ThisFileEnd Sub
I'm using this piece of code to go through Folders and their Subfolders. It works quite well in going through the first folder and its sub's but does not seem to generate a full list.
I am looking for specific files in these folders, and depending in what folder I place the file, it may or may not detect it. I require the code to go at least 3 levels deep (sometimes more).
FolderName = "C: est folder" ProcessFiles FolderName, "*.xls"
Code: '~~> This function was taken from '~~> http://www.vbaexpress.com/kb/getarticle.php?kb_id=245 Sub ProcessFiles(strFolder As String, strFilePattern As String) Dim strFileName As String, strFolders() As String Dim i As Long, iFolderCount As Long
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.
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.
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.
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 <> ""
I have created a macro named "SummaryCalculation" and I want to run this macro to more than 100 excel files which are saved in subfolders in a main folder. Each subfolders have atleast one excel file. I want the macro to be run with in these subfolders not the files are in main folder.
and for each Project in Projects, create a new folder with the actual month (e.g. "03" or "12")
Im running the Makro from a file where I'd like to put the month in a cell -> so the code refers to cell("A1") wich has value 01 and creates a folder "01" in every projectfolder in C:Projects
So I have a macro that creates a monthly set of reports, but some of them only relate to period 5 onwards. I wanted the macro to check whether a folder exists for periods 1 to 4, and if so, delete the folder and all the files inside it. I've used the following...
Code: If Period < 5 Then If Dir("I:AcctsCentral EngineeringEngineering Reporting Pack2012-131 April 20122-2 Reports - 4+8 Reforecast") "" Then Kill "I:AcctsCentral EngineeringEngineering Reporting Pack2012-131 April 20122-2 Reports - 4+8 Reforecast[code]....
but the macro just skips straight through the secondary IF statements without stopping.
I know this works on deleting files, and presumed it did too for folders, but it doesn;t.
I have created an appointment schedule spreadsheet. Once I get the spreadsheet running smoothly, I would like to create a worksheet for every day of the year that we are open.
I have decided to have one main folder with 26 subfolders in it. In each of those 26 subfolders, there will be one workbook with 12 worksheets in it. That will be two weeks worth of appointments as we are open Mon-Sat. Of course I want to name the worksheet tabs at the bottom of the workbook according to the appropriate calendar date. Then there is also a cell at the top of each page that also has the date, the same as the date on the tab. Just wondering if there is a simple way to create a macro to rename all these worksheet tabs, or if I have to physically open up each workbook, and rename all the worksheet tabs according to the calendar date. Then once the worksheet tab is named, can you make it automatically put the same date into Cell A1?
i am looking to create a macro that cycles through sub folders within a main fold and takes the same line of nformation from each workbook that it cintains.
the main folder is a yearly folder "2008" there a 12 subfolders within this named "january" to "December" (one for each of the months of the year) Within the monthly folder are four weekly forlders named "week 1" to "week 4"
each of the line in the workbook ferer to a different person so i will need to transfer all of them into individual summary workbooks. but in this example i need to take the information from A3 - K3 from each workbook.
Basically I have a large database of folders of examples of projects/notes etc, each with essentially lots of potential topic "tags". I want to sort them to be able to tell the macro what topic I am looking for and it give me the folders that contain that info. I will need to tag each folder individually (which is no problem). I am looking for a piece of script (that either exists or that I can write) that will do the following:
- tag specific folders with numerous "tags". The folders will all be stored in a database. The tags will be user input.
- sort these folders based on specified tags and show filepath/location/name/file number or something unique based on the tags input.
I'm looking to create a macro that does the following:
- Loops through a folder structure - Opens a specific subfolder within each folder based on name (i.e. "*Financials*") - Opens a specific file within that subfolder "*Financials*" based on both most recently modified a naming criteria (i.e. "*Model*") - Performs an action on that file (a macro created elsewhere that I assume I can call here) - Closes that file, and moves on to the next file matching the criteria above
As a self-diagnosed VBA novice, I'm having trouble adapting code found in various forums for my specific project.
I've found examples that address aspects of my desired macro or do similar things, but I can't figure out how to put them together.
Open most recent file:
[Code] .....
Loop through folders and subfolders and print all files:
I've created a Excel workbook with VBA code to synchronize an Access database between a laptop and a server. One of the fields in the database is a shortcut to a jpg for each record. (The Access stuff is not too important here)
Now I'd like to add the ability synchronize the photos between the laptop and the server; so people who use the server can view the photos added by the laptop and vice versa.
Something like:
Code: For each [JPG] in [LaptopFolder] If not [JPG] exists in [ServerFolder] then filecopy [LaptopFolder][JPG], [ServerFolder][JPG] end if next [JPG]
I am trying to write a macro to open a specific file, but need to search multiple folders within folders to find it.
The file name I need to open is "Escalation Adherence-Details " & Format(Date, "mm-dd-yy") & ".xlsx".
I need to drill down to the Adherence Report folder and then have the macro search through folders for each year (2012, 2013, 2014, 2015, etc) and then each month within each year (1 January, 2 February, 3 March, etc), at which point I would then find that day's file.
So far I have the following:
Code: Sub Open_ESCL_Report()
Workbooks.Open Filename:=*****.****.****.******.comsharesPurchasingTeam XEscalationAdherence Report & "Escalation Adherence-Details " & Format(Date, "mm-dd-yy") & ".xlsx" End Sub
Each file is stored in it's respective month folder as .....Adherence Report(Year)(Month)(File).xlsx
I have been given the following code to transfer data from multiple workbooks within folders and subfolders to retreive the same line of data from each of the workbooks and place them in a master workbook.
the folders are set up as follows,
there is a main folder, (a yearly folder) within this are 12 monthly folders (named January to December) within these are four weekly folders (named week 1 -week 4) contained within these weekly folders are the workbooks that i wish to copy data from.
for example a1 - k1
the code i am using transfers the file names but comes up with #REF! instead of transfering the data
I am trying to create a macro that will copy any folders that exist in any of the paths listed in the first column. The folders should be copied to the path of the open workbook containing the macro. Below is the macro I have currently, much of which was taken from information I found in this thread [URL]....
VB:
Sub wrapper3() x = 1 Set fs = CreateObject("Scripting.FileSystemObject") While Sheets("Air").Cells(x, 1) <> "" v = InStrRev(Sheets("Air").Cells(x, 1), "") dest = ActiveWorkbook.Path & Mid(Sheets("Air").Cells(x, 1), v, 99)
[Code]...
This code seems to work fine if all of the folders exist to be copied. My problem is that some do not and it is creating a "Path Not Found" error for which I need a fix. If the folder doesn't exist at the path nothing should be copied and the next path can be evaluated.
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?
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]....
I am totally new to both EXcel 2007 and Programming however i would really like to create a main folder using coloum A and then a subfolder within the main folder just created using coloum B.
I have looked on line and found some code but when i put/assign the code to a button it never appears to work.
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.