无法在 VBA 中使用 Getdetailsof 获取 Microsoft Word 文档属性

问题描述 投票:0回答:1

Image of Windows Explorer showing Program Name Property 我想获取一堆 Microsoft Word 文件的名为“程序名称”的属性。此属性在 Windows 资源管理器中可见。我尝试使用以下代码获取文件的所有属性:

Sub Property_List()
    Dim Folder_Path as String
    Dim File_Name as String
    Dim vShell as New Shell32.Shell
    Dim vRep as Shell32.Folder
    Dim vFich as Shell32.FolderItem
    Dim aPropName() as String
    Dim i as Integer
    Folder_Path = ".............."
    File_Name = ".................doc"
    Set vShell = CreateObject("Shell.Application")
    Set vRep = vShell.NameSpace(Folder_Path)
    Set vFich = vRep.Items.Item(File_Name)
    For i = 1 to 1000
        Redim Preserve aPropName(i)
        aPropName(i) = Format(i, "000:") & vRep.GetDetailsOf(vFich, i)
        If Len(vRep.GetDetailsOf(vFich, i) = 0 then
               ReDim Preserve aPropName(i - 1)
               Exit For
        End If
     Next i
    Dim vFSO As FileSystemObject
    Dim MyFile
    Set vFSO = New FileSystemObject
    Set MyFile = vFSO.CreateTextFile(Folder_Path & "\Prop List-" & File_Name & ".txt", true)
    MyFile.Close
    Set vFSO = Nothing
    Set MyFile = Nothing
    Set vFich = Nothing
    Set vShell = Nothing
    Set vRep = Nothing
End Sub

我已经参考了Resp在这个论坛上给出的答案。 Szwr 按照下面的链接 https://stackoverflow.com/a/50526660/16098242 我很感谢他提供的这段代码。 当我使用上面的代码时,我得到一个包含 36 个文件属性的文本文件。但是,我没有得到我正在寻找的“程序名称”属性。因此,我请求所有人是否可以帮助我获得该房产价值。 注意:我对 VBA 非常陌生,我正在借助此类论坛上的讨论来学习它。在上面的代码中,有些东西我不熟悉。因此,恳请您指导。 问候 我尝试使用上面的代码获取名为“程序名称”的属性,但我没有获取此属性

vba ms-word
1个回答
0
投票

此示例的输出包括“程序名称”:

'Add a reference: Microsoft Shell Controls and Automation
Sub GetFileAttributes()

    Const strFilePath = "C:\Temp\datavallistboxbasic.xlsm" 'for example
    
    Dim objShell As Shell32.Shell, objFolder As Shell32.Folder
    Dim objFolderItem As Shell32.FolderItem, i As Long
    Dim strFileName As String, aName As String, aValue As String, strPath As String
    
    strFileName = Mid(strFilePath, InStrRev(strFilePath, "\") + 1)
    strPath = Left(strFilePath, Len(strFilePath) - Len(strFileName) - 1)
    
    Set objShell = New Shell
    Set objFolder = objShell.Namespace(strPath)
    Set objFolderItem = objFolder.ParseName(strFileName)
        
    For i = 0 To 255
        aName = objFolder.GetDetailsOf(objFolder.Items, i)
        aValue = objFolder.GetDetailsOf(objFolderItem, i)
        'list only the attributes with a value:
        If Len(aValue) > 0 Then Debug.Print i & " - " & aName & ": " & aValue
    Next i
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.