从文件中检索扩展的属性

我确信这段代码可能看起来有点儿熟悉,但是我无法通过这个循环的文件path打印机代码获得文件的扩展属性。

  • 对象属性很容易使用Scripting.FileSystem object获得
  • 但是,当我尝试提取的扩展属性,我得到的错误对象不支持此属性或方法“

我是否需要创build它自己的shell?

代码失败:

  Cells(i + ROW_FIRST - 1, 3) = objFolder.GetDetailsOf(objFile, 9) 

现有的代码

 'objFSO: A Scripting.FileSystem object. Private Function GetAllFiles(ByVal strPath As String, _ ByVal intRow As Integer, ByRef objFSO As Object) As Integer Dim objFolder As Object Dim objFile As Object Dim i As Integer i = intRow - ROW_FIRST + 1 Set objFolder = objFSO.getfolder(strPath) On Error Resume Next For Each objFile In objFolder.Files 'print Date created Cells(i + ROW_FIRST - 1, 1) = objFile.DateCreated 'print file name Cells(i + ROW_FIRST - 1, 2) = objFile.Name 'Author------>!!!! HERE IS THE PROBLEM !!!! Cells(i + ROW_FIRST - 1, 3) = objFolder.GetDetailsOf(objFile, 9) 'print file path Cells(i + ROW_FIRST - 1, 4) = objFile.Path 'Insert doc link Cells(i + ROW_FIRST - 1, 5).Select ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _ objFile.Path, _ TextToDisplay:=objFile.Name i = i + 1 Next objFile GetAllFiles = i + ROW_FIRST - 1 End Function 

谢谢!

你需要为此使用Shell

在我的系统上, Author属性是20。

 Sub HoldtheDoor() Dim oShell As Object Dim oDir As Object Dim objFile As Object Set oShell = CreateObject("Shell.Application") Set oDir = oShell.Namespace("c:\temp") For Each objFile In oDir.Items Debug.Print oDir.GetDetailsOf(objFile, 20) Next End Sub