VBA Code To Find Last Modified Document In A Folder
Dec 18, 2012
I currently have a code that searches a folder, opens a spreadsheet, and then copies over the "Status" tab to the Master document.
New spreadsheets will be created a couple times a week, so I would like the code to be able to search this folder for the most recently modified document and then open THAT document.
So, if my folder has..
Report 10May11
Report 05May11
Report 17May11
Then, I would want a code to search in this folder for the most recently updated document (in this case "Report 17May11.xlsx) and then go through the step I have above where it copies over the various tab.
Basically, this code would I guess replace the example code I have below.
Sub WorkbookOpen()
....
End Sub
View 8 Replies
ADVERTISEMENT
Jul 23, 2014
I 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.
View 9 Replies
View Related
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
Jan 4, 2012
I'm using VBA to query file information (path, name, size, dates, etc.) on files on a SharePoint site and returns them to Excel. I'm curious if also returning the document's permissions is possible. If not for the document, can one programmatically get the folder's permissions?
View 6 Replies
View Related
May 30, 2009
way to bring more efficiency in this code.
I need to run this code on 100,000 rows every week and this takes hours to finish.
View 14 Replies
View Related
Jan 29, 2006
I'm trying to modified this line code. The 1st line code below opens a dialog box where you wan to save it.
strPictureFile = Application.GetSaveAsFilename("", "JPEG Files (*.jpeg), *.jpeg", , "Save as JPEG")
Now here I tried to modified it to just save it in a file folder as a jpeg. But its giving me a error. Am I missing something?
strPictureFile = Application.SaveAsFilename = "C:MyPictureD.jpeg"
View 9 Replies
View Related
May 18, 2007
Anyway to use VBA to print an Excel sheet with the Microsoft Document Image Writer to a specified folder automatically? I understand and use automatic printing all the time, but I don't know how to use VBA to specify the filename and folder once it prints with the Document Image Writer.
Is it possible to do?
View 9 Replies
View Related
Feb 10, 2014
I copied this snippet from the net and it has been working like a charm. I would like to add DateLastModified to it, but I can't get it to work, I'm still kind of new to more complex VBA codes. Here is the code...
Code:
Private Sub CommandButton1_Click()
Dim cell As Range
Dim selcell As Range
Dim Value As String
Dim Folder As Variant
Dim a As Long
ReDim Folders(0)
Set cell = Range("B8")
[Code] .........
View 7 Replies
View Related
Mar 11, 2014
I needed a code that would input the current date and time in the cells in column N whenever changes were made to any cells in the row from columns A to M. For example, if I change a name in cell 6D, then cell 6N would automatically change to the current date and time.
I found a useful code on a forum (maybe here, don't know for certain) and modified it to suit my needs (see below). I am however now getting a debugging error suggesting that the second line that reads "Private Sub Worksheet_Calculate()" is causing an error.
View 11 Replies
View Related
Jul 4, 2008
My company uses a customized accumulative code week system, as in the year 2000 to today is about 442 weeks with the year 2008 starting around week 416.
Here is how my formula works(or how I would like it to work), if the date (in cell F8) is blank, nothing is displayed, if there is a date (format 2008-07-03) and it falls within 2008, WEEKNUM+416(416 is a fixed reference in J4), if the date falls within 2009, WEEKNUM+416(J4)+52, if the date falls within 2010, WEEKNUM+416(J4)+104. I only need it to go from 2008 to 2010.
This way J4 is a fixed code week reference where 416 is added to each week number, but it does not work for years 2009 and 2010 as it does not add the weeks from the starting reference.
Here is a copy of my formulas:
=IF(AND(F8)=0,""*(IF(AND(F8)
View 9 Replies
View Related
Jul 31, 2014
I have an excel database where I register cases. I have in it a button that creates a folder with and ID nr that is in column A (I create new ID nr in the next row, when I press the button it will create a folder with that ID nr and inserts a blank word document in it). We have a template that we copy to the folder (depending what type of case). The idea would be that once the template is filled in and ready to print, It would take the values from the ID nr and a reference number a few cells to the right. Is it possible to tell excel to open the word document in the folder and create a PDF version with the ID nr and reference number. (there are only 2 templates, so the macro would have to look for one of the two in the folder) The names of the templates are: "Standard" and "Other". I guess the best way to start maybe this would be that I select the cell with the ID nr and then press a macro button to have this done. One thing that needs to be done, is to put a copy in the same folder and another in a second folder called "Binder" in my documents folder.
View 1 Replies
View Related
Jul 8, 2009
I have my VBA Code set up to open a specific file and copy paste that information into this open spreadsheet in a particular sheet.
The only problem I have is that I don't know how to close the document once its opened.
I know that I can manually close it, but I want my macro to take care of it for me.
If anybody has suggestions, they would be greatly appreciated.
Here is my code so far to help out.
Sheets("Ann Ret Data").Select
Range("A1").Select
Workbooks.Open Filename:="P:InvINVpubAndrew EdgarMarket Value Projectperformance_data.xlsx"
Columns("A:G").Select
Selection.Copy
Windows("Qtr-End Market Value Project2.xlsm").Activate
Range("A1").Select
ActiveSheet.Paste
Also the file I want to close is the Performance_Data.xlsx file.
View 9 Replies
View Related
Jun 14, 2007
I have a two documents whose names contain periods out of 70. Example is St._Paul and St._Louis_Park. When I run through the code it stops it with the error that the name cannot be found. My list looks like this..
Club Name
Eagan
Apple_Valley
St._Paul
etc.
When I remove the period it works. Is there a way to make it work with the period in there so I don't have to change a bunch of files and documents? Here is the code...
Sub OpenUp()
Dim wb As Workbook
Dim ws As Worksheet
Set wb = Workbooks(ThisWorkbook.Name)
Set ws = wb.Worksheets(1)
With ws
TotalRow = .Cells(1, 255).End(xlDown).Row
Finalrow = .Cells(TotalRow, 1).End(xlUp).Row
End With
For i = 2 To Finalrow
clb = ws.Cells(i, 2)
psw = ws.Cells(i, 3)
psw2 = ws.Cells(i, 4)
mnth = ws.Cells(i, 5).........................
View 5 Replies
View Related
Nov 19, 2012
I am experiencing odd behavior with Excel (v. 14). When a spreadsheet is opened, format setting of almost all cells in the workbook have changed to a custom code that reads "[$-409]0%". AFAIK the first part is not even a valid tag.
Because the underlying data is not changed, I can just select cells and reset formatting to "Number" or "General" and everything's fine. However, I'd like to get to to the root of the problem.
The problem occurs with only some workbooks. I should mention that the workbooks are circulated in different language versions of Excel, which may contribute to the problem.
View 2 Replies
View Related
Mar 17, 2014
I have been automating reports that will be generated in word documents for every company. The baseline is that I have a excel sheet which contain the data inputs and a word template document (template with bookmarks). I have written a macro that generate the reports when the user clicks the button but found that there some reports that generates empty bookmarks since there is no data for the corresponding bookmark. I have uploaded the excel sheets that has the full data and the setup sheets. The setup sheet has the Column Number, Bookmark Name, Description. The data sheet has the data values and the code info sheet has the name of the template doc and the name of the destination folder where the reports will be generated and stored. My requirement is to delete the empty bookmark from the report named "Blackberry". where to write the macro for deleting the empty bookmarks and its sentences (whether its in excel book or word template doc)?
View 3 Replies
View Related
Apr 8, 2009
If possible could someone please tell me why the below code is not calling the normal.doc macro "testy" and any solutions.
The code opens a new document, pastes the text from the clipboard and then fails to run the wanted macro.
View 6 Replies
View Related
Jul 17, 2014
I'm trying to get certain Excel cells (varies by column and row) to populate different areas in a Word document. I've tried using both Word bookmarks and form fields and have defined the Excel names with the Word bookmark names as well as using Word's generic terms (Field1, Field2, etc.) with no luck. The VBA code I'm using now is for word forms and will open the Word document but seems to delete the form fields. I don't know if I'm not coding the cells correctly or what.
Sub CreateProposal()
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
Set wdApp = CreateObject("Word.Application")
' Open word document
[Code] ........
View 3 Replies
View Related
Nov 9, 2009
I currently have this code that allows me to print a word document on one of my drives with the click of a button in excel. I need to modify it because one of the files I want to print as well is a pdf file. how to modify it so I can do that?
Set appWrd = CreateObject("Word.Application")
Set docOpen = appWrd.Documents.Open("F:groupsdeptservCDTISA.doc")
docOpen.PrintOut
docOpen.Close
appWrd.Quit
View 9 Replies
View Related
Sep 22, 2009
I have the following info in a table:
name | doc date | doc value
a | 2009/01/01 | IN111
b | 2009/02/04 | IN222
c | 2009/02/05 | IN333
a | 2009/01/05 | CN111
d | 2009/03/01 | IN444
b | 2009/03/01 | CN222
a | 2009/04/01 | IN555
Firstly, I need to find the LAST DOCUMENT DATE for "a" where #doc_value starts with IN*** (invoice). Manually, I can see that it would be "2009/04/01", but my spreadsheet runs 6000+ entries. I need a function to do this.
Secondly, I need to find the corresponding #doc_value for that date (in this case, IN555).
View 9 Replies
View Related
Feb 2, 2014
I am processing a fair few Invoices, which are being sent to me via e-mail as excel documents, very often they contain mistakes, a decent amount of mistakes. Usually the prices are wrong.
I keep track of every single entry on the invoice on my own document - Tracker, which I consider to be the superior/more correct document to the Invoice presented to me by my contractor.
Both of the documents have a reference number, which is a specific docket number, and horizontally, in the invoice, there is going to be a price for this docket. In my document, there is going to be a separate column for the total price.
Is it possible (I guess with VBA) to check for mistakes in the Invoice, but use the Tracker as a reference for this check.
Tracker has
columns
A - Name
B - Department
C - Date
D - Docket No.
C - Total price for the docket (calculation of E to Z)
E to Z - all smaller entries
Invoice has
columns
A - Date
B - Docket No.
C to E price for that docket, but it is spread, because departments are separated out, so each VAT account can be charged accordingly. I guess it is possible to do a separate column for the price, if it is easier to do a script that way.
Basically, I need to check if in the Invoice document, the price (C to E) for Docket No. (B) is the same as the price (C) for the Docket No. (D) in the Tracker.
I would like the wrong entries to be highlighted on the Invoice Document, so I can see straight away, that this needs attention.
Not always the price is wrong, sometimes the Docket No. is spelled incorrectly (Dyslexic contractor), hence the highlighting.
View 3 Replies
View Related
Feb 17, 2009
I need a script that will turn a excel doc into a txt doc. Thats the easy part. The hard part (at least I think it is), is I need it to be in a certain format and I'll do my best to explain that fomat below.
View 9 Replies
View Related
Jun 3, 2009
I am having an issue with trying to find anyone's desktop folder. I'm trying to write a path to the desktop but once again the desktop is different on every computer. The problem line is in red.
View 8 Replies
View Related
Apr 11, 2012
Is there a way to find a folders path? I have a folder Dropbox
I want to find the path up to this folder on the current computer. Is there a method to accomplish this?
I am fine if you want to give VBA code so I can put it in my immediate window for now and then I can attempt to add it to existing code later.
So an Example of the possible result would be
Directory is C:MyNameUserDropbox
Or on another computer maybe C:User1ListingFilesDropbox
View 9 Replies
View Related
Apr 10, 2007
I have created a separate SAVE button that when the user hits that button, it saves the file in a network drive using the current date as part of the save-file name. Ie: Sheet20070408.xls, Sheet20070409.xls, Sheet20070410.xls, and Sheet20070411.xls.
I am currently working out all the "idiot proof" safety features. My code looks something like this:
oldfilename = ActiveWorkbook.FullName
newfilename = "C:NetworkFolder" & format(date, "yyyymmdd") & ".xls"
ActiveWorkbook.SaveAs Filename:=newfilename
ActiveWorkbook.SaveAs Filename:=oldfilename
Why am I saving it twice? When the user clicks SAVE, I want to save over the copy of the current sheet they use, even if they save it on their desktop, and then save it to the network drive. This way, if they keep a second copy in an easy to find location, it will save the data to that sheet as well. Just in case they forget to save on the current sheet. I need to be sure each copy of the file has the most up-to-date information, as well as save a copy for retention.
My question is this: Can I search a folder for an existing file name? If the user goes into the network drive to open an old file for retention and they click SAVE, I don't want to accidentally overwrite a file in the retention folder.
View 4 Replies
View Related
Jun 2, 2014
I have a code that gives me path of all files inside a folder. I want to modify it.
I want to select files (individually or in group) inside a folder and then get the path. All files are .xlsx in folder.
[Code] .....
View 1 Replies
View Related
Jun 11, 2014
I want to get source code of htm file. The files are on my folder (E:SepehrData).
The files names are like A2 [F1].htm, E2 [F4 conv].htm, E2 (DC L180G).htm and etc.
I want to bring all source code (with the tags, ) on a worksheet at column A in cell A1.
Example below.
HTML Code:
--------------------------------
<!DOCTYPE "-//DTD HTML //EN " html public>
<HTML>
<HEAD>
****** content="Vanemeze">
****** charset="ISO">
</HEAD>
<BODY>******** type="text/javascript" src="..showHide.js">
[Code] ..........
View 2 Replies
View Related
Sep 13, 2006
I have a macro that creates a spreadsheet on a weekly basis and have been using it for quite sometime. Due to the large number of spreadsheets I would like to incorporate some code that would create a folder every month. I would assume that the code would need to include a check routine to see if a folder for that month exsists.
View 3 Replies
View Related
May 23, 2008
this query has now took a peculiar twist in the fact that my boss now wants to change the goalposts
here is a thread with the code in
[url]
View 14 Replies
View Related
Oct 29, 2008
I am doing a project for work at the moment where by I have to manipulate a report compiled by an external program and do various bits and bobs to it. Trouble is, the other program creates a new version every time it runs the report (i.e filename.1.xls, and the next day filename.2.xls, and so on). Is there any way of searching the folder these files are in to find the newest file and select that one as the one to open and manipulate? There will be no files other than these in the folder.
View 5 Replies
View Related
Apr 10, 2009
How could I find the next .xls file in the current folder using VBA?
View 9 Replies
View Related