Time stamp

  • Thread starter Thread starter JB
  • Start date Start date
J

JB

When I close a document I would like to have the time it was saved at the
top of the document. How is that done, please?

JB
 
You could use a savedate field eg { SaveDate \@ "HH:mm" } which will record
the last time the document was saved when the document is next opened, but
the field will not update automatically as you make saves to the document
during the course of working - it will however fulfil the basic criterion of
recording the time.

Or you could intercept the FileSave command to add a document variable to
the document and update it each time the document is saved and if you have a
docvariable field in the document - here { DocVariable varSaved } - that
field will display the time the document was saved and update each time you
save.

Sub FileSave()
Dim oVars As Variables
Dim sDate As String
Dim oStory As Range
Dim oField As Field
Set oVars = .Variables
With ActiveDocument
oVars("varSaved").Value = "Last saved at " _
& Format(Time, "hh:mm")
For Each oStory In .StoryRanges
For Each oField In oStory.Fields
If oField.Type = wdFieldDocVariable Then oField.Update
Next oField
Next oStory
.Save
ActiveWindow.Caption = ActiveDocument.FullName
End With
End Sub
http://www.gmayor.com/installing_macro.htm


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Hello Graham

You may remember that you helped m with a Mavro: SaveToTwoLocations. At
the time, I left it at that.

Could I add something to that particular macro, which is working fine, so
that it stamps the time of saving?


Sub SaveToTwoLocations()
Dim oDoc As Document
Dim strFileA As String
Dim strFileB As String
Dim strBackupPath As String
'Define the backup location
strBackupPath = "C:\Documents and Settings\Qimi\Desktop\Backups\"
On Error Resume Next
Set oDoc = ActiveDocument
With oDoc
'Mark the cursor position with a bookmark
.Bookmarks.Add Range:=Selection.Range, Name:="OpenAt"
.Save
strFileA = .FullName
strFileB = strBackupPath & "Backup " & .Name
.Close 'Close the document
End With
FileCopy strFileA, strFileB 'Copy the document
Documents.Open strFileA 'Reopen the original document

ActiveWindow.View.Type = wdPrintView
'and restore the cursor position
ActiveDocument.Bookmarks("OpenAt").Select
End Sub




Thank you
 
If you mean you want the time written in the document as opposed to in the
filename then the two macros can easily be combined. Put a docvariable field
{ DocVariable varSaved } at the location where you wish the time to appear.

Sub SaveToTwoLocations()
Dim oDoc As Document
Dim strFileA As String
Dim strFileB As String
Dim strBackupPath As String
Dim oVars As Variables
Dim sDate As String
Dim oStory As Range
Dim oField As Field

'Define the backup location
strBackupPath = "C:\Documents and Settings\Qimi\Desktop\Backups\"
On Error Resume Next
Set oDoc = ActiveDocument
With oDoc
Set oVars = .Variables
'Mark the cursor position with a bookmark
.Bookmarks.Add Range:=Selection.Range, name:="OpenAt"
oVars("varSaved").Value = "Last saved at " _
& Format(Time, "hh:mm")
For Each oStory In .StoryRanges
For Each oField In oStory.Fields
If oField.Type = wdFieldDocVariable Then oField.Update
Next oField
Next oStory
.Save
strFileA = .FullName
strFileB = strBackupPath & "Backup " & .name
.Close 'Close the document
End With
FileCopy strFileA, strFileB 'Copy the document
Documents.Open strFileA 'Reopen the original document

ActiveWindow.View.Type = wdPrintView
'and restore the cursor position
ActiveDocument.Bookmarks("OpenAt").Select
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Back
Top