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.
Related
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
I am producing a file everyday with updated market data (the layout is identical each day, just different numbers in the tables). I have a couple of columns on each worksheet that take data from a separate file. This file has a date as part of its name.
One formula is:
=K10-'O:\Daily Vols\PDFsourcefiles\[Daily PDF 2018.05.18..xlsm]POWERPDF'!$K$10
This equation gives me the data in K10 today minus the data in K10 from yesterday's document.
I would like to find a way to automatically update this file path each day with the previous date on which I ran the file (NOT just date-1 as weekends can't be included!)
I am currently using 'find and replace' function but this is very time consuming and prone to human error if I forget one or two cells.
I do have today's date in cell A1 of the 'Comments' worksheet if this would be useful to use.
I hope someone out there with more experience of excel will be able to help with this - many thanks in advance!
This should be doable in VBA. I think the Workbook_Open event would be best. The link will be made when you open the file. Assuming you don't know how to get to the VBA editor press Alt+F11 and double-click "ThisWorkbook". Then type the following code:
Private Sub Workbook_Open()
Sheets("[YourWorksheetName]").Cells([RowNum],[ColNum]) = "=K10-'O:\Daily Vols\PDFsourcefiles\[Daily PDF " & Format(Date - 1, "yyyy.mm.dd") & "..xlsm]POWERPDF'!$K$10"
End Sub
Where [YourWorksheetName] is the name of the worksheet of today's file (maybe POWERPDF?), [RowNum] and [ColNum] are the row/column that you want this formula. So if this formula goes into B1 then it would be .Cells(1, 2) because B is the second column.
Hopefully that works better.
I am a beginner at visual basic and this is my first stack overflow question, so I'm sorry if this is a mess. I am trying to take values entered from a windows form and enter them into an excel sheet. I used search and replace to achieve this. I have been able to successfully get that far. My only problem now, is that excel will not calculate the values entered into the sheet. Excel will only calculate those functions if I manually go in and reset each cell (with F2). I have my calculation on automatic as well.
Dim excelReplacements As New List(Of Array)
' Create list to hold hold excel replacements
excelReplacements.Add({"utilCost",
ExclusiveUtilityRate.Value + SharedUtilityRate.Value})
excelReplacements.Add({"intCost", Internet.Value})
excelReplacements.Add({"pCost", PhoneCost})
excelReplacements.Add({"pUnits", PhoneQty.Value})
'Select sheet 2
workbook.Worksheets("Sheet2").Activate()
Try
'loop though excelReplacements and replace every key with it's value
For Each rep In excelReplacements
Dim ranges As CellRange() =
sheet.FindAllString(Convert.ToString(rep.GetValue(0)), False, False)
For Each range As CellRange In ranges
If rep.GetValue(0) Is "pCost" Then
sheet.Replace("pCost", Convert.ToDouble(PhoneCost.Value))
ElseIf rep.GetValue(0) Is "pUnits" Then
sheet.Replace("pUnits", Convert.ToDouble(PhoneQty.Value))
Else
Dim value As Long = Convert.ToDouble(rep.GetValue(1))
sheet.Replace(range.Value, value)
End If
Next
Next
Catch e1 As System.Exception
'if couldn't find the word,give a message
Console.WriteLine("The text doesn't exist the word you want to replace")
End Try
Output.AppendText("Changes Made...")
' save workbook
workbook.SaveToFile(xlssave, FileFormat.Version2013)
workbook.Worksheets.Remove("Evaluation Warning")
xlsApp.Quit()
Output.AppendText("Worksheet Saved" & Environment.NewLine)
I have done a lot of research, but I have only found information on vba, which I am not using. I
I have the following imports:
Imports System.IO
Imports System.Runtime.InteropServices
Imports Newtonsoft.Json
Imports Excel = Microsoft.Office.Interop.Excel
Imports Spire.Xls
Imports System
Imports Microsoft.Office.Interop
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
If you need more of my code I will gladly show you. If there is any way to force a full calculation using vb.net (praying there is) or if you see an error in my code that is causing excel to not calculate the values, please let me know.
Try xlsApp.CalculateFull. The calculation methods work at the application level, not the workbook level.
The .Calculate method also works at the Worksheet and Range level. This may also help as calculating a smaller range will be quicker than doing the full calculation across all open workbooks in the application.
If you modify the VB code, the Excel spreadsheet using it does not realize it's changed and so does not recalculate. However, anything that convinces Excel to recalculate a cell containing a call to the now modified VB function will force it to execute for that cell. Also editing the cell, even just hitting F2 and Enter, will work. However, if you have a lot of cells using the function, it would be a pain. A Solution I've found: do a Find and Replace of the (full) function name and click Replace All... bingo!
I would add the .Calculate Method in order to force calculate.
I want to create an excel template that will includes formulas for dating the columns. However, since those formulas will be based on TODAY(), I need to convert them to static strings (so the dates don't change everytime someone opens it). Is there a way to add a macro that will run automatically when someone creates a new spreadsheet based on the template? (Similarly to Auto_Open(), only on Create, rather than Open). If so, I could just create a macro that will replace the formulas with their results upon document creation. Can this be done?
[Note: I'm not married to this solution; it just seemed like the simplest way to protect my spreadsheet. If someone can suggest an alternative approach, I'd be obliged.]
I have a couple thoughts...
If you run a copy/paste values macro every time it really won't matter, right?
You could check if the file exists yet (has been saved), and if not
then this must be the template opened as a new workbook, maybe?
Code:
Private Sub Workbook_Open()
If Dir(ActiveWorkbook.Name) = "" Then
'run the macro?
MsgBox "I'm gonna run this macro"
End If
End Sub
You could have a cell on one of the sheets, that will never be used,
or is hidden, that will store whether or not to run the macro, and
change that when the file is opened or when the macro is ran. Then
have a macro run on open that checks that cell. (Or custom/document property)
You could populate the cells that have the today() formula only on
open and if they are already populated then don't run the macro?
I realized that there is no need for a Workbook_Create() function, as that behavior can be emulated by simply deleting the macro after it has run once (which happens when it is first created). Deleting macros is done automatically when the file is saved with a .xlsx extension. In addition, you need to prevent the macro from running when you open the template itself (while editing the it). You can hold the SHIFT key when opening it to prevent auto-run macros, but since that method isn't foolproof, I added this code at the top:
Private Sub Workbook_Open()
'If we're opening the template, don't run the macro
If Application.ActiveWorkbook.FileFormat = xlOpenXMLTemplateMacroEnabled Then
Exit Sub
End If
...
'add code here to SaveAs .xlsx, thus removing the macros, so it won't run every time.
End Sub
(Note: I didn't show my SaveAs code as it is rather messy: I wanted to suppress the default warning about losing macros, but wanted to also protect the user from inadvertantly overwriting previous file. If anyone is interested, I could post it)
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.