View Full Version : Last save time
Mr Von
10-04-2020, 03:17 AM
Hello everybody,
sorry for my bad English. the 1st code works wonderfully. the 2nd code doesn't work. no error is displayed
Sub myMacro()
Dim strName As String
  strName = Application.UserName
  Application.UserName = InputBox("New last author")
  With ActiveWorkbook
    .BuiltInDocumentProperties("Last author") = Application.UserName
    .Save
  End With
  Application.UserName = strName
  ActiveWorkbook.Close
lbl_Exit:
  Exit Sub
End Sub
Sub myMacro()
Dim myDate As String
Dim strDate As String
  myDate = "2012-05-01 00:30:00"
  strDate = myDate
  
  With ActiveWorkbook
    .BuiltinDocumentProperties("Last save time") = CDate(strDate)
    .Save
  End With
  myDate = strDate
  ActiveWorkbook.Close
lbl_Exit:
  Exit Sub
End Sub
Please help, thank you
p45cal
10-04-2020, 04:30 AM
I strongly suspect the last save time will be a read-only property.
Why do you want to distort the truth on User and Savetime ?
Mr Von
10-04-2020, 05:24 AM
I don't want other people to see when I've been working on a file.
In that case you'd better use paper and pencil instead.
Paul_Hossler
10-05-2020, 08:51 AM
https://docs.microsoft.com/en-us/office/vba/api/excel.workbook.builtindocumentproperties
Returns a DocumentProperties (https://docs.microsoft.com/en-us/office/vba/api/office.documentproperties) collection that represents all the built-in document properties for the specified workbook. Read-only.
Sorry
p45cal
10-05-2020, 09:13 AM
SorryAh but, ah but, ah but: MS doesn't always tell the truth; if the OP is correct that his first macro snippet works swimmingly, then the built-in document property Last Author is read/write!
Even if it is overwritten in the Activeworkbook.close Event (when else) ?
Paul_Hossler
10-05-2020, 03:59 PM
Ah but, ah but, ah but: MS doesn't always tell the truth; if the OP is correct that his first macro snippet works swimmingly, then the built-in document property Last Author is read/write!
1. Ahh -- I suspect that it the COLLECTION DocumentProperties that is Read Only then, and not the Items
2. Some properties are update-able, but some are not - couldn't find a list, so it's trial and error time
27269
3. I thought I'd try to be clever and change the system time, save the file, and reset the system time, but couldn't get this to work
Option Explicit
Type SYSTEMTIME
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMilliseconds As Integer
End Type
Dim lpSystemTime1 As SYSTEMTIME, lpSystemTime2 As SYSTEMTIME
Declare PtrSafe Function SetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As Long
Sub SaveWithOldDateTime()
    With lpSystemTime1
        .wYear = 2000
        .wMonth = 1
        .wDayOfWeek = -1
        .wDay = 1
        .wHour = 1
        .wMinute = 1
        .wSecond = 0
        .wMilliseconds = 0
    End With
    
    With lpSystemTime2
        .wYear = Year(Now)
        .wMonth = Month(Now)
        .wDayOfWeek = -1
        .wDay = Day(Now)
        .wHour = Hour(Now)
        .wMinute = Minute(Now)
        .wSecond = Second(Now)
        .wMilliseconds = 0
    End With
    
    
    'set the new time
    SetSystemTime lpSystemTime1
    ThisWorkbook.Save
    
    SetSystemTime lpSystemTime2
    ThisWorkbook.Saved = True
    ThisWorkbook.Close
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.