How to get the "Last Saved By" property for a workbook file

In Windows Explorer, if I right-click the file and select "Properties" to get the "File Properties" window and then select the "Details" tab, the property indicated there is "Last Saved By" appears. It seems that the Windows account name was registered the last time the file was changed.

I looked in FileSystemObject, but I do not see that the File object has such a property.

How do I get this property in VBA? Is there a Windows API for Windows?

UPDATE:

There are three attempts in this thread to do this with Shell GetDetailsOf. I appreciate the efforts, but it seems pretty clear to me, having tried them (especially the OssieMac code example), that the text stored in the "Last Saved By" field on the file system was not found in GetDetailsOf.

Scratched his head. How does Windows Explorer do it?

+4
source share
2 answers

Try this - the code uses the BuiltinDocumentProperties class:

Option Explicit

Sub Test()
    MsgBox LastAuthor
End Sub

Function LastAuthor() As String
    LastAuthor = ThisWorkbook.BuiltinDocumentProperties("Last Author")
End Function

EDIT

- Microsoft , Author 9. Windows, Vista 20 - . . 10 Windows 10.

Option Explicit

Sub Test()

    Dim varPath As Variant
    Dim varFileName As Variant

    varPath = "C:\Users\foo\bar\" '<~~ ensure final \
    varFileName = "lol.xlsx"


    'depending on OS version, try 9, 10 and 20
    Debug.Print GetAuthorFromShell(varPath, varFileName, 9)
    Debug.Print GetAuthorFromShell(varPath, varFileName, 10)
    Debug.Print GetAuthorFromShell(varPath, varFileName, 20)

End Sub

Function GetAuthorFromShell(varPath As Variant, varFileName As Variant, intProperty As Integer) As String

    Dim objShell As Object
    Dim objFolder As Object
    Dim strAuthor As String

    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace(varPath) 

    With objFolder
        strAuthor = .getdetailsof(.Items.Item(varFileName), intProperty)
    End With

    GetAuthorFromShell = strAuthor

End Function
+4

Extended File Properties NTFS. , script:

Dim arrHeaders(266)
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("C:\Test.xtx")
For i = 0 to 265
 arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
Next
For Each strFileName in objFolder.Items
 For i = 0 to 265
 Wscript.Echo i & vbtab & arrHeaders(i) _
 & ": " & objFolder.GetDetailsOf(strFileName, i)
 Next
Next

, . Windows 2000 35, Windows Vista - 266.

:

1) Windows PowerShell, 2:

2)

+1

Source: https://habr.com/ru/post/1664504/


All Articles