从文件

时间:2016-05-26 22:07:54

标签: excel vba excel-vba

我确定这段代码可能看起来有点熟悉但我无法使用此循环文件路径打印机代码获取文件的扩展属性。

  • 使用Scripting.FileSystem object
  • 可以轻松获取对象属性
  • 但是当我尝试提取扩展属性时,我得到错误 Object不支持此属性或方法“

我是否需要创建自己的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

谢谢!

1 个答案:

答案 0 :(得分:0)

您需要使用Shell

在我的系统上,作者属性为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