[Macro] Why this script still cant get last modified time? i have checked the api. thx

krsto e. shared this question 56 days ago
Discussion Open

hi, i simply want to use macro to grab the current map's last modified time.


code:

Sub Main()
    ' Ensure there is an active document

    ' Access the current document's properties
    Dim doc As Document
    Set doc = ActiveDocument

    ' Retrieve the last modified time
    Dim lastModified As Date
    lastModified = doc.DocumentProperties.ModifiedTime

    ' Display the last modified time in a message box
    MsgBox "The document was last modified on: " & lastModified
End Sub

when run, it show error at line: lastModified = doc.DocumentProperties.ModifiedTime

52fe4d9639d381baa5c9d32d36f45ad6


but i have checked in the api that it do exist:

15492fb569b13f2137cc341c4b9d00ad


either GPT4 or C3.5 helped me wrote useful, working winwrap script so i dont think there is wrong logic. many times they halluciate a non existing function and now i checked the function/method exist. and the script is just several lines i dont think it could be complex.


would like to seek help, thanks.


btw i simply would like to make a macro that grab the file's last modified time and write back into the file somewhere, thanks

Best Answer
photo

solved.


DocumentProperties itself is a data type. not under document object.


working code example:

Sub Main()
    Dim doc As Document
    Set doc = ActiveDocument

    If doc Is Nothing Then
        MsgBox "No active document found."
        Exit Sub
    End If

    ' This is a guess - we need to confirm how to get DocumentProperties
    Dim props As DocumentProperties
    Set props = doc.Properties  ' or maybe GetProperties() or something similar

    If Not props Is Nothing Then
        MsgBox "Last modified time: " & props.ModifiedTime
    Else
        MsgBox "Unable to access document properties."
    End If
End Sub

Replies (1)

photo
1

solved.


DocumentProperties itself is a data type. not under document object.


working code example:

Sub Main()
    Dim doc As Document
    Set doc = ActiveDocument

    If doc Is Nothing Then
        MsgBox "No active document found."
        Exit Sub
    End If

    ' This is a guess - we need to confirm how to get DocumentProperties
    Dim props As DocumentProperties
    Set props = doc.Properties  ' or maybe GetProperties() or something similar

    If Not props Is Nothing Then
        MsgBox "Last modified time: " & props.ModifiedTime
    Else
        MsgBox "Unable to access document properties."
    End If
End Sub

Leave a Comment
 
Attach a file