Add Folders To All Directories Within Another Directory?
Nov 29, 2012
I am trying to automate some of the work I used to do as I have moved to another position, specifically trying to automate file management. I am using this code to create new files for each client
Code:
Public Sub CheckDir(fold1 As String)
If Dir(fold1, vbDirectory) = "" Then
MkDir fold1
Else
End If
End Sub
which works great, but you still have to do one client at a time. Basically I'm using this code to create new client files, but each year we will need to add a directory and sub directories for every client in a certain directory. What I would like to do is code a macro that would add say a "2013" folder with all appropriate sub directories to every client folder within the folder that contains all of the client folders The folder hierarchy should look like this
Code:
'F:Clients
'F:ClientsClientName
'F:ClientsClientName2013
'F:ClientsClientName2013RandomOtherFolders
I assume it would use a For/Each, but I'm not sure how to go about it.
View 3 Replies
ADVERTISEMENT
Aug 22, 2006
I would like to create a list of folder/directories in the current directory. The only code I've been able to find lists all files in the current directory (not folders).
View 3 Replies
View Related
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
Sep 12, 2007
I am trying to specify all files and folders in a directory and the only help I found was the following thread: Create Index Of Files In Folder That works really well but, what I need is to specify all the folders and all the files under a directory, does any of you awsome hacks have an idea of how I can enhance the macro if the thread posted above?
View 3 Replies
View Related
Jun 28, 2014
Code that loops through all folders in a directory, to check each workbook in each of those folders. If any workbook name in any of these folders matches a predefined string, then open this workbook for some other codes to run.
View 2 Replies
View Related
Feb 5, 2010
I was searching through the internet to look for some help with regards to consolidating data from multiple workbooks from different directories into a single worksheet called Summary.
I would like to copy the entire worksheet from different workbooks in different directories into this workbook I like to call Summary. To manually do it I have to open the workbook I want to copy the worksheet from. Right click on the tab and select Move or Copy, select the sheet I want to copy and select the workbook I want to copy this sheet to. Repeat this process for all the workbooks.
The next step is to copy and paste from these sheets into a main summary sheet. The data range from these sheets are starting from row 13 onwards and they may be of different size between Column A to Column W.
For example the workbooks are coming from :
S:Area 1West.xls from worksheet Andy
S:Area 1East.xls from worksheet Bill
S:Area 1North.xls from worksheet John
S:Area 1North.xls from worksheet Albert etc...
View 9 Replies
View Related
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
Dec 20, 2011
I have folders with different assigned folder icons based on the content in the folders.
I would like to arrange these folders in the window based on the assigned folder icons and then by alphabetical order.
How it is to be done. Can we make use of vba having the folders path list in one column of excel sheet?
View 9 Replies
View Related
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
May 21, 2014
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
View 4 Replies
View Related
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
Mar 31, 2014
I want to open C:Projects
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
View 3 Replies
View Related
Sep 5, 2013
The script collects all the files in directory and sub-directories and list them in ascending format, I want them to get in transpose format. like for example: Root folder has many sub directories and in them a sub directory XYZ has 5 excel files, it will get the sub directory name in Col A and transpose all .xls files.
Col A | Col B________|Col C_________ |Col D___________|Col E________|
XYZ__|C:/root/test.xls|C:/root/Sales.xls |C:/root/Report.xls |C:/root/sam.xls|
[URL]
View 8 Replies
View Related
Feb 5, 2010
I need to use VBA to test if a certain directory exists and if not ten create it.
I do this with:
[CODE]Sub MakeDir()
Dim DirName As String
Dim FileName As String
Dim fnameshort As String
FileName = "C:TestA1ATest.xls"
fnameshort = Right(FileName, Len(FileName) - InStrRev(FileName, ""))
DirName = Left(FileName, Len(FileName) - (Len(FileName) - InStrRev(FileName, "")))
If Dir(DirName) = "" Then
MsgBox "Does not exist"
'Dir to be created using MkDIr
End if
End Sub/CODE]
My problem is that I need the script to loop back until it finds a folder that exists, and then make the respective subfolders.
Example:
C:TestA1A should be created, but currently only C:TestA exists.
VBA should then test for the full path, and when it finds out, that it does not exist, it should strip off one folder, test for that and so forth.
When it finds an existing folder, it should then make the respective subfolder, and then the subfolder to that...
View 9 Replies
View Related
Mar 2, 2009
In my Excel file, I have three columns: A, B and C. Column A holds the folder names. column B holds the files hash names. And in column C, i keep the files real names, i.e:
A1.value = Contract folder
B1.value = 23ffryu567894lkgj090
C1.value = picture1.jpeg
On my hard drive, I have all the folders (column A data) already created inside a folder called directories: E:directories... There is another directory on my drive in which I keep all the hash files: E:infiles
And all I would like to do now, is to write a piece of code to read all three columns row by row and based on the data in that row, moves the hashed file into their proper directories and rename them to their real name. In the example above, the program should read the data found in the first row: A1, B1 and C1 and move the hash file named 23ffryu567894lkgj090 to E:directoriesContract folder and rename the hash file to picture1.jpeg
View 14 Replies
View Related
Nov 8, 2007
I have a folder structure like ex this c:my folders. Under this folder i have several folders and subfolders. I would like to use a macro to run through all this folders an sub folders and change the name of the first letters of all folders.
Ex
LOP-100-APPL
LOP-200-ORG
I would like to change LOP to PLP instead. I'm lazy and looking for a method for not doing this job manually. This should be done from the excel workbook.
View 3 Replies
View Related
Sep 19, 2008
I am trying to access and copy some data from the excel file which is located in different folder each time I run the new macro. The file got the same name but only the folder name is different each time.
e.g File is called "testfile", but I have a list of subfolders something like that
date_time (folder name)
15-02-2008_2122 (folder name)
15-03-2008_2189 (folder name)
Each of the above subfolders contain "testfile" with new data and they all are located in the same drive and same mainfolder. Note my Macro file is located in a different drive.
I want when I run the macro all I have to do is to enter Date and macro will automatically pick up the right folder and the right file ("testfile") inside that folder and do all the required task.
View 9 Replies
View Related
Jun 10, 2009
I am trying to prompt the user for the directory to be saved in and file name to be saved as; then save the workbook in the input directory with the inputted file name.
View 3 Replies
View Related
Jan 4, 2011
Is there any way to reference a directory that is up one level from the ActiveWorkbook.Path?
I am trying to accomplish three goals:
1. Maintain a Master Database in a root directory and pull data from a subdirectory - EASY:
VB : FilePath = ActiveWorkbook.Path & "sub-DirectoryName"
2. Maintain a Minor Database located in a sub-Directory, Named by Month, and pull data from the Master Database located in the Root Directory (up one level). Which I cannot find the right syntax for - ".." does not work.
3. Maintain a Minor Database in a sub-Directory, Named by Month, and pull data from a different Minor Database in a Different sub-Directory (e.g. up one level to root directory, then down one level to "January"). Which I also cannot find the right syntax for.
The Databases are going to be moved around A LOT, so I have to use relative paths.
View 4 Replies
View Related
Feb 13, 2010
search an entire drive from the root directory and down into all subfolders and copy all files matching various file types below to another drive into organized folders named for the file type. (for an example any .xls files in F: copy to G:xls .xls files) and also create an index in one excel file showing all the files in alphabetic order with its original path.
bmp
txt
xls
View 14 Replies
View Related
Oct 7, 2007
Create sub directories from Cell Values
I Need a VB macro to Create sub directories unless sub directory already exist. My file will be Save 5 Level deep. Each Sub Directory will be cell value in a Worksheet .
Example C:CategoryYearSeriesMonthBimonthlyFile Name.xls
I will be using this in over 100 different files so I want to be Generic as possible
View 6 Replies
View Related
Jan 18, 2008
I am trying to do is loop through a series of directories under a target directory. When a directory is found, it looks within that directory and finds any .xls files, loops through those and copies/pastes them to the new target directory. I have managed to get it to work only on the first iteration of the loop through the directories, then it crashes. The error code is "Invalid Procedure Call or Argument." Here's the
If valFilePath = True Then
MsgBox (msg)
Else
'Search for directories within source directory
strDir = Dir(ebsSource & "", vbDirectory)
'If a file has been found
Do While strDir <> ""
If strDir <> "." And strDir <> ".." Then
strFile = Dir(ebsSource & "" & strDir & "" & "*.xls")
Do While strFile <> ""
'Copy .xls files and paste in destination
copySource = ebsSource & "" & strDir & "" & strFile
copyDestination = ebsDestination & "" & strDir & "" & strFile
FileCopy copySource, copyDestination
strFile = Dir
Loop
End If
'Crashes here after looping through the first iteration of Excel files
strDir = Dir
Loop
View 2 Replies
View Related
Mar 20, 2008
I found this nifty program on[url]but there is a problem with it and it's down to the types of files I'm trying to list on my PC.
The excel code below lets you select a starting directory and it will then produce a list of files in a sheet. However when it comes across an internet shortcut file it gets rather confused and won't display the name of the shortcut but what the shortcut stands for. This causes an issue when I try and get some details about the file (eg date, size etc.) as a 'permission denied' error can then occur if it links to a file that is currently in use. For some reason I can't attach an example of a shortcut / internet shortcut so please feel free to make one at your end. eg. I have a shortcut called 'ImageJ' which links to a web address [url]. The code below then reports this address instead of the file name 'ImageJ'. Can any one suggest how to amend this coding to handle this issue?
Option Explicit
'Requires a reference to:
' Microsoft Shell Controls and Automation (shell32.dll)
'Uses techniques found here:
[url]
Public objShell As IShellDispatch4
Public Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
View 5 Replies
View Related
Feb 26, 2009
I have a CSV file and would like to create directories on my hard drive and the names of those directories will need to be pulled out from this csv file: [B1:B86].
For example I have the following data in my csv file:
B1: folder1
B2: folder2
.
.
.
And would like to create folders on my hard drive so that folder names will be: folder1, folder2, ...
View 9 Replies
View Related
Apr 5, 2007
I have a fluid document that I have to save for historical reasons in 2 separate directories. My save Macro works I was just wondering if anyone see's a better way of accomplishing saving to two separate directories then closing the document. I used the record function to gernerate most of the code.
Sub SAVEANDEXITTHESLATE()
Dim date1
Dim date2
Dim xlCalc As XlCalculation
xlCalc = Application.Calculation
Application.Calculation = xlCalculationManual
On Error Goto CalcBack
Application.ScreenUpdating = False
date1 = Now()
date2 = Format(date1, "mmm d yyyy hh mm")
ActiveWorkbook.SAVE
Application.DisplayAlerts = False
ChDir "c:Documents and SettingsmeDesktop"
ActiveWorkbook.SaveAs Filename:= _...................
View 5 Replies
View Related
Jan 28, 2010
I would like to create a macro which finds data from multiple worksheets and collates them in my Master Worksheet.
I am competent with a lot of functions with Excel, however I have never used Macro's before. I have a little bit of VB knowledge, but only the very basics. I will attempt to explain my situation as clearly as I can.
Please note in your response that I am not familiar with a lot of the programming jargon. I also do not know how to actually create (or is it record?) a macro.
Finally, before I dive into it, I would *prefer* not to have to add code to the closed worksheets, but I can do this if there is no other way!.......
View 14 Replies
View Related
Aug 17, 2012
Is there an easy way to populate a combobox with a list of directories on the hard drive?
I want to create a way for a user to specify a file without having to type in the full address by hand.
I would like to start in the c:/ root and list the directories in one combobox and the excel files in another combobox. Then if they select say "desktop" it displayes the directories in "c:/desktop" and the excel files contained there in. Then if they click test it does directories in "c:/desktop/test" and so on.
View 2 Replies
View Related
Feb 22, 2014
I have a master workbook that has been set up to mirror the structure of a single worksheet in various other workbooks saved in different directory locations. I need some VBA code to retreive specific data from a specified worksheet in multiple workbooks which are saved in different directories and then copy the data to the master workbook, listing each data set one after another. I do not want to open any of the source workbooks to acheive this.
I attach two example workbooks to better explain:
The code has to look in various sub directories to find the relevant workbooks, (Source1) then find the specified worksheet, (Stock) and copy only rows that have data from column B to O. The data needs to be copied to the master workbook, (master) from all the source workbooks as a list with no space.
View 4 Replies
View Related
Mar 31, 2009
What I have is four folders that are labeled 2006, 2007, 2008, 2009. In each of these folders are numerous .xls files. "2006.BS.03.xls" is a name of one of the files in the 2006 folder. All the files have the same nameing structure.
When somebody created the template for these files, they inserted a bitmap image instead of a jpg. So the file size is over 4mb. I have changed the image in the template from a bitmap to a jpg and the file size is now 197kb. That is a big change.
So what I am wanting to do replace the bitmap with a jpg in all the .xls, that have a certain naming structure, that are in the four folders.
Attached is the workbook that I have planned to have open and click a command button to do all the work.
I have got this to work on one file, but can't figure out how to get it to do multipile.
View 7 Replies
View Related
Jun 20, 2008
I have about 20 plus workbooks in a folder. Each has 52 sheets, Fridays date, that I want to copy all the data from each sheet.
Is there a way to open all workbooks in a folder and copy all data from on all the various sheets into a single workbook?
I'm trying to gather the info and make a small data base from the various books. I'd like not to have to call each workbook by name as the file names change or get added to.
View 11 Replies
View Related