How do I insert a last saved date field

Malc45rpm

New Member
Joined
Apr 25, 2003
Messages
4
I have an excel document which is linked from a web page. It is constantly modified and is viewed by several colleagues. I want to make them aware when the document was last updated by inserting an automatic 'last saved' comment on the opened document. The comment should include date, time and if possible 'modified by'.
Is there anyway of doing this? :confused:

Malc
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
you might be able to use/modify this. you will need to have a 'log' sheet

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, _
nSize As Long) As Long


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

On Error GoTo carryon
Application.ScreenUpdating = False
Dim lpBuff As String * 25
Dim ret As Long, UserName As String
ret = GetUserName(lpBuff, 25)
UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
Sheets("log").Activate
lastrow = [a1].CurrentRegion.Rows.Count
'add username date and time
Sheets("log").Cells(lastrow + 1, 1).Value = Application.UserName
Sheets("log").Cells(lastrow + 1, 2).Value = Date
Sheets("log").Cells(lastrow + 1, 2).NumberFormat = "mmmm d, yyyy"
Sheets("log").Cells(lastrow + 1, 3).Value = Time
Sheets("log").Cells(lastrow + 1, 4).Value = UserName
Application.ScreenUpdating = True
ActiveWorkbook.Saved = True
carryon:
End Sub
 
Upvote 0
ermm :confused: :confused: :confused:
I haven't got a clue what you're talking about, I was expecting a simple answer :LOL:
Sorry, I am not an excel expert, this is just a basic document, so if you could make it any clearer I would appreciate it! I am using Excel '97 in windows 98

Malc
 
Upvote 0
If you want it really simple, here's how to do a very simple version.

You'll need either a separate info sheet in your book, or a couple of cells somewhere that they aren't going to be overwritten.

I named the 2 cells "mod_opr" and "mod_tme". You can name them whatever you wish.

Hit Alt-f11 to open the VB editor

On the LHS double click on the "ThisWorkbook" and copy this into it.

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) 

Range("mod_opr") = Application.UserName
Range("mod_tme") = Date & "  " & Time
End Sub

Private Sub Workbook_Open()
MsgBox ("Last modified by " & Range("mod_opr") & vbCrLf & vbCrLf & "on " & Range("mod_tme"))
End Sub

I am assuming that you don't have macros in this already. :)

I hope this helps.

Cheers

Barry

edit: damned typos.
 
Upvote 0
I got the following message:

Run time error '1004':

Method 'Range' of object'_Global' failed

I then tried it again with "mod_opr" and "mod_tme" (including the speech marks) Same thing happened. I clicked Debug, but to be honest I don't really know what I am doing here! (straight over my head).

Does it matter which cell I am in when I go to the VB editor? I was in an empty one.

Sorry to be so dumb, but we all have to start somewhere :(

Malc
 
Upvote 0
That's alright. No need to apologise. Like you said, we all start somewhere. :)

It looks like you haven't named your cells.

Go to the cell that you want to name "mod_opr". There's a little box in the top left that will have an address like "C1" (or whatever the active cell is).

Click in that box, and type in "mod_opr" (wihtout the exclamation marks).

Repeat for the cell you want "mod_tme" to be in.

Your macro should now work. :)

If you have any problems, feel free to email me the sheet (but do me a favour and zip it first).

Cheers
 
Upvote 0

Forum statistics

Threads
1,216,616
Messages
6,131,757
Members
449,670
Latest member
ryanrodgers2014

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top