Consulting

Results 1 to 9 of 9

Thread: Last save time

  1. #1
    VBAX Newbie
    Joined
    Oct 2020
    Posts
    2
    Location

    Last save time

    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

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,873
    I strongly suspect the last save time will be a read-only property.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    Why do you want to distort the truth on User and Savetime ?

  4. #4
    VBAX Newbie
    Joined
    Oct 2020
    Posts
    2
    Location
    I don't want other people to see when I've been working on a file.

  5. #5
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    In that case you'd better use paper and pencil instead.

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    https://docs.microsoft.com/en-us/off...mentproperties

    Returns a DocumentProperties collection that represents all the built-in document properties for the specified workbook. Read-only.
    Sorry
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  7. #7
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,873
    Quote Originally Posted by Paul_Hossler View Post
    Sorry
    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!
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  8. #8
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    Even if it is overwritten in the Activeworkbook.close Event (when else) ?

  9. #9
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Quote Originally Posted by p45cal View Post
    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

    Capture.JPG


    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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •