I successfully used the code in in one of your answers to display the Last Saved Date in my excel project. The code that I used is:
Function LastModified() As Date
LastModified = ActiveWorkbook.BuiltinDocumentProperties("Last Save Time")
End Function
It worked like a charm for about a month. However, since that time, the save date fails to update automatically. I have to unprotect the sheet, run the macro manually (usually I just select the cell and hit 'ENTER'). I'm not aware of any structure type changes in the excel file that might account for this. Does anyone have any thoughts as to what could be preventing the code from running?
Try making your function Volatile:
Function LastModified() As Date
Application.Volatile
LastModified = ActiveWorkbook.BuiltinDocumentProperties("Last Save Time")
End Function
Related
I want to automatically download financial data by using Excel and save that data. The download of the data is done by an Excel add-in. ISINs are used as the data identifier. The process looks as follows:
Open Workbook
Replace the existing ISIN with a new one
Download data
Export data
Close file
The data download is done by a custom function which is defined inside the Excel Add-in (and which I cannot access as it is password protected): INFGETHIST(), one function parameter is an ISIN. Unfortunately, the function does not load the data until the VBA macro I am using to update the ISIN and close the workbook afterwards is fully executed - which means, the workbook gets closed before the data is updated.
I've tried the following
Application.CalculateFullRebuild
Calculate and
Sub WaitUntilFinished()
Application.Calculate
If Not Application.CalculationState = xlDone Then
DoEvents
End If
End Sub
but to no avail.
I'm searching for a way to trigger the download of the data before my code executes completely. Any ideas much appreciated.
I've got a spreadsheet that imports some data from a website and then filters and sorts it into a list. It reimports the data every 5 minutes.
I also have a cell, cell O1 located on the worksheet called FinalDisplay, that uses the following formula to timestamp when the last update occurred:
=TEXT(NOW(),"hh:mm AM/PM")
Lastly, I have a macro, called FilterSort that filters the list and then sorts the remaining results. This macro works fine when I run it manually.
What I am trying to do is have the change event of cell O1 getting updated at the time of the reimport trigger the macro to run so that, when the data is imported, it is automatically re-filtered/sorted. When the re-import happens and the timestamp is updated, however, nothing else happens.
The problem I think is that I think the Now() function getting recalcuated may not be handled as a change event because when I just punch in a number and overwrite the formula, the macro fires and everything works.
I've read that Now() is (or can be) a "volatile function" which might be handled differently than what I am expecting. Am I correct in thinking that this is the problem? Is there a way to resolve it so that the macro is called when the timestamp cell is updated?
I have a custom Excel-Function
Public Function getDate(interval, no)
getDate = Format(DateAdd(interval, no, Date), "dd.mm.yyyy")
End Function
When I enter this function in a cell it works as expected.
However, when I open a file, which does already have the function used, it produces an #Value! Error.
Example input of a cell: =">" &getDate("ww";-1) normally the result is:
>30.07.2015
I do also use the Bloomberg Excel-Addin and have Bloombergfunctions used in cells. But these work without any problems.
Does anyone have an idea how to fix it?
best regards
This is either a partial answer or a full answer. Your function contains Date -- which suggests that you want the function to be Volatile but UDFs are non-volatile by default. If you put
Application.Volatile
as the first line in getDate then it will update automatically as the date changes.
Perhaps the problem is that when you open a file at a later date Excel somehow detects a dependency on the date but is unable to recalculate it. I can't reproduce your bug and I don't have this Bloomberg Addin, so I don't know if this is the bug, but it does seem like a bug.
Another thought -- to use add-ins you don't need to save as a macro-enabled workbook but to use UDFs you need to. I don't think this is the problem, but you should double-check that it is saved as a macro-enabled workbook and that is opened with security settings which enable it.
If these suggestions don't solve it -- see if you still get the error without that add-in installed.
Does anyone know how to display the Last Saved Date of an Excel Spreadsheet on one of the worksheets?
I have found ways to do it using macros, but the spreadsheet is populated by an add-in called Jet Essentials, and this does not like macros so a solution here must not use one.
thought I would update on this.
Found out that adding to the VB Module behind the spreadsheet does not actually register as a Macro.
So here is the solution:
Press ALT + F11
Click Insert > Module
Paste the following into the window:
Code
Function LastSavedTimeStamp() As Date
LastSavedTimeStamp = ActiveWorkbook.BuiltinDocumentProperties("Last Save Time")
End Function
Save the module, close the editor and return to the worksheet.
Click in the Cell where the date is to be displayed and enter the following formula:
Code
=LastSavedTimeStamp()
This might be an alternative solution. Paste the following code into the new module:
Public Function ModDate()
ModDate =
Format(FileDateTime(ThisWorkbook.FullName), "m/d/yy h:n ampm")
End Function
Before saving your module, make sure to save your Excel file as Excel Macro-Enabled Workbook.
Paste the following code into the cell where you want to display the last modification time:
=ModDate()
I'd also like to recommend an alternative to Excel allowing you to add creation and last modification time easily. Feel free to check on RowShare and this article I wrote: https://www.rowshare.com/blog/en/2018/01/10/Displaying-Last-Modification-Time-in-Excel
May be this time stamp fit you better
Code
Function LastInputTimeStamp() As Date
LastInputTimeStamp = Now()
End Function
and each time you input data in defined cell (in my example below it is cell C36) you'll get a new constant time stamp.
As an example in Excel file may use this
=IF(C36>0,LastInputTimeStamp(),"")
You can also simple add the following into the Header or Footer of the Worksheet
Last Saved: &[Date] &[Time]
There is no built in function with this capability. The close would be to save the file in a folder named for the current date and use the =INFO("directory") function.
I have an Excel add-in (Bloomberg) which streams real-time prices into a spreadsheet. I need to add a column which contains the last time a price was updated. I've tried to do this with the worksheet change event, but this doesn't seem to get fired by the changes (I assume something to do with it being a real-time update).
The requirement is the same as the question below, but the solutions do not apply since the events do not fire in this case.
automatically execute an Excel macro on a cell change
With help from another forum, I've found an easy way to do this.
First define a function as below in a VBA module accessible to the sheet:
Public Function GetTime(target As Double) As Double
GetTime = Now()
End Function
Then in the 'last updated' column, add a call to this function with the formula pointing to the cell you wish to monitor. Whenever the target cell is updated, even from a real-time update, the function will fire and cause the time to be updated.