[Macro] Why this script still cant get last modified time? i have checked the api. thx
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
but i have checked in the api that it do exist:
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
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 Subsolved.
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 Subsolved.
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 Subsolved.
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---