Extract Folder Name
Aug 6, 2007if I have a workbook sitting in a folder, how to I extract that foldername with VBA. Not the full path or the filenmae - just the folder name?
View 9 Repliesif I have a workbook sitting in a folder, how to I extract that foldername with VBA. Not the full path or the filenmae - just the folder name?
View 9 RepliesI need a macro in a workbook to look at all the files in the same folder that have "*att*.xls" in the name and determine and copy from the range A15:W515 only the rows that have data in at least columns A, C and D. Each file will vary as to how many rows there will be and there are more than the files with "*att*.xls" in the folder. The data will be on the only worksheet in each file and the worksheet is named "G2WAttendee_xls" the data from all the files need to be copied to the file called "Consolidated webinar reports.xls" (I am using Excel 2003) and to a sheet called "Attendance Data" and added to the end of the last paste.
At the start of the macro the current file "Consolidated webinar report.xls" should be saved to a sub folder of the current directory and have the date saved added to the name. The sub folder is called "Completed reports". The data in the original file on worksheet "Attendance Data" should be deleted.
At the end of the process all the files that have had data copied from them should be moved to the sub folder "Attendance reports consolidated" (This could be done as each file is closed if that is easier).
I have headings in row 1 of the "Attendance Data" worksheet that match the headings in the various files in the folder (which will always be in row 14 of the individual "*att*.xls" files).
The folder with all the files and the "Consolidated webinar report.xls" file is at path "Z:P and S MEvaluationsWebinar series 2012-13TB".
I have a list of excel and word files in a folder...200+ of them. They all have the Author, Subject and Category populated under the File- Properties menu. From browsing through the site, I came across bits that suggest it is possible to do the following: Code that will run through a list of word/excel files in a designated folder, and extract the Excel(or Word) filename, Author, Subject and Category into a new excel file as a list?....................
View 6 Replies View RelatedI am using some code to loop through a folder and extract some data from a specific sheet.
Now say a user moves the file to another folder etc... The macro will pull up an error, now is there a way i can have it dynamic linked to the spreadsheet so no matter what folder it gets moved to,
My folder path will adjust to that or need to take another route?
The code below looks at file names in column A and then goes to a folder and opens and copies the data in range c2 -lastrow from each file and pastes the data into sheet2.
how I could add to the code so that it also inserts the file name in column c?
It would make it easier to track the data in column B.
VB:
Sub CopyFromFile()
Dim fPath As String
Dim lRow As Long
[Code].....
I have attached a sample workbook. The list of file name is in sheet 1. An example of the output is in sheet 2. The data in column A is dummy data generally spans 100's of rows not just 10 as in the example.
The purpose of the code is to be able to put a list of file names in column a in sheet 1 and extract data from those files in a folder. The data extraction works fine. The reson for adding the file names is so that I know what file the data came from.
I have alot of project folders on my harddrive.
All in format: I:/12345-costumer-projectname/
The five digits are unique for each project.
I make calculations for these projects using an excel file. In this excel I also type the projectnumber (cell J2)
Now i would like to make a button. When pressed, it checks the projectnumber cell J2, looksup the corresponding folder and saves the excelfile in PDF format in this folder.
I have found macro to find files in folders, but none which do the above.
I have up to 50 workbooks in one folder with data in a specific range. I also have one workbook which includes additional data, including conditional formatting and dropdowns. I need to copy the desired range from the first workbook in the source folder to the second workbook, then save the latter to my destination folder, using the same name as the first. I need to repeat this process for all workbooks in the source folder.
View 2 Replies View RelatedI have an Excel VBA Macro for creating/logging drawing numbers. Each drawing belongs to a job number. Each job number has a folder name containing the job number followed by a description (ie 999999 - bracket assembly) for storing drawing pdf's. The job number is only known as a 6 figure number in the drawing creation process BUT for the PDF saving process it is a string value...as my example above
I have to change my process by pre-creating the Job Number folder, then have the macro look for the appropriate folder by searching the parent folder for a sub folder containing the job number (always the first 6 figures).
I want to insert in my macro some code that searches...
The parent folder for a folder containing the job number. The macro value for the parent folder is P:engineeringdrawings (this never changes). the macro value for the job number is iOpenair (it's an entry that is entered as start the macro). Imagine the value for the job number is "999999"...so the search would be for "999999*.*" The code needs to search the parent folder, find the folder name that begins with a six digit number. Capture the complete name of the folder and store that name as a Dim value that I can call up elsewhere in my macro.
I am creating a document for work that automatically generates hyperlinks to pdf files in a given sub folder. Currently I have a section of code that opens a window to choose the folder location.
Code:
'Prompt user to select a directory
Do
Problem = False
Set ShellApp = CreateObject("Shell.Application"). _
Browseforfolder(0, "Please choose a folder", 0, "c:\")
On Error Resume Next
[Code] ........
What I actually want is to not have the window open, but excel automatically choose the sub folder location.
The directory looks like this
Z:ClientProjectDRAWINGS-2 RECORD COPIESPDF
The xlsm file is stored in the DRAWINGS folder, and I need it to point to the PDF folder.
I have a list of items in an excel sheet... 500 of them... and there are images for them in an other folder... The problem is those images are in 1000's and I only need those 500 images.. Images are saved as "SKU.jpg eg NS2354.jpg and we have an SKU column in excel as well .. SKU and their images have same name...
Is there any solution to pick up only those 500 images from those thousands of images?
Is it possible to save those 500 images in an other folder?
looking for some code to save to a destination
destination address is
C:Documents and SettingsstDesktopOJF
now the problem is OJF has folders named 1 to 500
so if cell d5 = 487 it will need to look in the above desination and then open the folder and save it there.
I would like to create a code that will open all workbooks in folder "A" one at a time and then close the work book after another code is executed. So one workbook will open and while the workbook is open, I will call another code to format the active workbook and then the active workbook will be saved in folder "B" and closed and go to the next workbook in folder "A" to start all over. The folders are saved on the desktop.
View 5 Replies View Relatedif it's possible to use XlDialogOpen to open up a folder that you only have part of the name.
For example, say you have the following folder paths:
C:Main FolderSubfolder1Smith,Billy 2413
C:Main FolderSubfolder1Brown,Charlie Ray 2416
C:Main FolderSubfolder1Bunny,B 3619
C:Main FolderSubfolder1Fudd,E-G 1864
What I'm hoping to do is just look for the 4 digit number on the end finding that folder name and opening it up. The name conventions before the 4-digit serial number are quite random. Sometimes it includes their full first name, other times it's just an initial for the first name and other times there are other characters included in the name. The one thing that is constant is the 4 digit serial number on the end.
how I could get the Open dialog box to pop up and have the chosen folder number open?
Is there a way I can from vba cut a file from a folder and put in to another folder? And also create a folder? If yes, how can I do this?
Is it better to use dir or scripting.filesystem object?and if there is an advantage to use one over the other.
I have a column "ID" which contains ID . In the next column I want to get the name of the folder which contains a word file with same name as ID.
View 2 Replies View RelatedI have a macro that creates a folder from an active cell in A1. I know want to have it create the folder and create a hyperlink.
Sub MakeFolder_Rev1()
FolderLocation = "G:TST shared filesHonda Problem & IPPAAR-IPP TrackingHTR PROBLEM TRACKING SHEETS67 KiHTR Communication & Documents"
CurrentRow = ActiveCell.Row
FolderName = Range("A" & CurrentRow).Value
[Code]...
How can I get just the inner Folder (red) in this path? Example given.
C:Working_DirectoryPersonalFolder
I am trying to figure out a way to open a folder through VBA. I just want the G: drive to open and then it lets the user navigate any folder within the G Drive and select which ever file they choose to open.
View 1 Replies View RelatedHow do I write this to always save in a particular folder? C:Documents and SettingsErinDesktopJob Cost Estimates and how is it different if I am using a shared network?
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim varFileName As Variant
varFileName = Application.GetSaveAsFilename(Range("G6"), _
fileFilter:="Excel Files (*.xls), *.xls")
If varFileName False Then ThisWorkbook.SaveAs varFileName
End Sub
this is my folder path:
\c06661Documents and SettingsptliDesktopPresentationDatabase Common Driver
\c06661: is my Full Computer Name
Database Common Driver: is my folder name
how can use the VBA code to access this path to access My Folder
I am trying to save a file to a different directory but am not having any luck with the syntax.
so far have created new folders on the X drive. The x drive folders have been assigned a variable name which I am attempting to use again when telling the save as function where to save the file. the variable name is not being picked up in the new macro. I have declared the variable name as public at the start of my module.
I currently am using fileSearch but am now having to update my code because of Excel 2007. I ran into a problem and am now redoing my code.
I need an example without using fileSearch to loop through each .xls and .xlsx file in a particular folder
What I had:
With Application.fileSearch
.SearchSubFolders = True
.NewSearch
.Filename = ".xls"
.LookIn = UserFile
.FileType = msoFileTypeExcelWorkbooks
.Execute
ffc = .FoundFiles.Count
For i = 1 To ffc
I am a bit rusty at VB because I haven't had to do it in a while, and my searches on the board for help on this haven't got me to the right info yet.
Is it possible to have saved the same workbook name and that to have a prompt asking whether you want to replace or update the workbook??
eg. If update, it'll scan through the existed workbook & compare with the other workbook which you want to save, & add rows according or sum up the total for one of the cols.
I am trying to record macros, however, without success. When I launch Excel, two spreadsheets, PERSONAL and Personal Macro Workbook are launched. However, when I attempt to record a macro in a new spreadsheet, I get an error message, "Personal Macro Workbook in the startup folder must stay open for recording".
Looking in the XLSTART folder, I see two files, as noted above.
I want to know how to index a drop down list to be used for calculations.
Up until now I was using
Range("B1").Select 'the cell where the drop down list is
ActiveCell.Formula = SiteID 'site id
But for whatever reason it trims a trailing zero from SiteID when setting it in the second line. SiteID is a VBA string.
Indexing it would work, as would preserving the zero so help on either one is appreciated. Auto Merged Post Until 24 Hrs Passes;Correction, I lied. I was using this line to set it.
Range("B1").Select 'the cell where the drop down list is
ActiveCell.FormulaR1C1 = SiteID 'site id
I have created a browse button in excel and assigned a macro which will ask the user for folder. I figured it out for windows using Windows API Functions as mentioned at http://www.cpearson.com/excel/BrowseFolder.htm. However cannot get it to work for a Mac.
View 2 Replies View RelatedIs there and API call I can do to determine a user's default add-in folder for Excel add-in ?
View 9 Replies View RelatedI am using this code:
VB:
Sub a()
Dim WB1 As Workbook, WB2 As Workbook, MyFile As String, Sep As String, WS As Worksheet
Dim R As Range, X As Integer, a As Range, b As Integer, rownum As Integer, WS1 As Worksheet
Dim R2 As Range, a2 As Range, row As Integer, sep2 As String, MyFile2 As String
[Code] ....
If I run this code without the miles of code i have between them, it loops through each workbook in the folder just fine.
However, I am getting a Runtime 5 error when it reaches Myfile = Dir() each time with my full code.
Here is the full code:
VB:
Private Sub CommandButton1_Click()
Dim WB1 As Workbook, WB2 As Workbook, MyFile As String, Sep As String, WS As Worksheet
Dim R As Range, X As Integer, a As Range, b As Integer, rownum As Integer, WS1 As Worksheet
Dim R2 As Range, a2 As Range, row As Integer, sep2 As String, MyFile2 As String
Sep = Application.PathSeparator
[Code] .....
Once again, I am getting the error message 3 lines from the very bottom ("MyFile = DIR()")
i want if i insert picture name in a cell it should get picture from a specific folder.
View 3 Replies View RelatedI have a column on a spreadsheet containing the last four (XXXX) or in some cases six (XX-XXXX) if there are duplicates of the last four SSN. I manually enter these as needed. I also create a folder that will be named the last four or six in the same format that is in the excel spreadsheet. Is there a simple way to automate the linking of these cells to the external folders?
View 3 Replies View Related