You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

获取Windows资源管理器中Word文件的Program Name属性

解决Word文件“Program Name”属性枚举缺失的问题

你用的常规VBA枚举方法仅获取了基础Shell属性,而Windows资源管理器显示的"Program Name"属于扩展属性,需要遍历更完整的Shell属性索引范围才能捕获到。以下是修正后的VBA代码,可以枚举更多属性:

Sub EnumerateAllFileProperties()
    Dim objShell As Object
    Dim objFolder As Object
    Dim objFile As Object
    Dim intPropIndex As Integer
    Dim strFileName As String
    Dim strOutputPath As String
    Dim intFileNum As Integer
    
    ' 设置目标Word文件路径和输出文本文件路径
    strFileName = "C:\Test\Sample.docx"
    strOutputPath = "C:\Test\FileProperties.txt"
    
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace(Left(strFileName, InStrRev(strFileName, "\")))
    Set objFile = objFolder.ParseName(Right(strFileName, Len(strFileName) - InStrRev(strFileName, "\")))
    
    intFileNum = FreeFile()
    Open strOutputPath For Output As intFileNum
    
    ' 遍历更大范围的属性索引(0到500,覆盖多数扩展属性)
    For intPropIndex = 0 To 500
        Dim propName As String
        Dim propValue As String
        propName = objFolder.GetDetailsOf(objFolder.Items, intPropIndex)
        propValue = objFolder.GetDetailsOf(objFile, intPropIndex)
        
        If propName <> "" Then
            Print #intFileNum, "属性索引: " & intPropIndex & " | 属性名: " & propName & " | 属性值: " & propValue
        End If
    Next intPropIndex
    
    Close intFileNum
    Set objFile = Nothing
    Set objFolder = Nothing
    Set objShell = Nothing
    
    MsgBox "属性枚举完成,结果已保存至: " & strOutputPath
End Sub

使用说明:

  1. 打开Word,按下Alt+F11打开VBA编辑器
  2. 插入新模块(右键项目 -> 插入 -> 模块)
  3. 粘贴上述代码,修改strFileName和strOutputPath为你的实际路径
  4. 运行代码,生成的文本文件会包含所有可枚举的Shell属性,其中就包括"Program Name"

关键说明:

  • 原代码可能只遍历了小范围的属性索引,而Windows Shell的属性索引范围远大于36,扩展属性通常在更高的索引值区间
  • 循环到500基本可以覆盖绝大多数常见的文件属性,若仍有缺失可适当调高上限

内容的提问来源于stack exchange,提问作者CMMaliniJoshi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 20:24:52