Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 4th, 2005, 12:58 PM
Registered User
 
Join Date: Dec 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default File Information

Hi all,

I'm trying to use a macro to get specific file properties of a file.

I've tried using a Scripting.FileSystemObject and I've tried the FileSearch.FoundFiles object.

What I'm after is the Owner/Author/Comments that you can see in Explorer, and as far as I can see, neither the above two objects hold that information.

Note - these are not excel files.

What might be nice is a copmlete reference to what information is available in either a FileSystemObject, or a FoundFiles object!!

Any assistance appreciated.
 
Old December 4th, 2005, 01:00 PM
Registered User
 
Join Date: Dec 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh - one more point....

You can get the properties I want from ActiveDocument.BuiltinDocumentProperties, but only for the current document! I want them for any document in the filesystem.

Thanks,

Andy
 
Old December 9th, 2005, 06:43 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Andy,

Couple of points here. Firstly you can get a lot of information about what properties and methods object contain by looking at things in the Object Browser. This can be found in the VBE by pressing the icon button at the top of a box with a triangle, square and circle coming out of it. From this window you can narrow your search to a particular library by selecting the top drop-down box on the LHS. The info you get will relate to all the methods and properties you can call on objects and sometimes (if you're lucky!) you'll get a sparse description of what the the method / property means at the bottom of the window. Its often not really enough but the listing will give you an idea of what might be achievable with the object in question.

Now to your actual problem. You really need to use Shell32 to get this done. You will need to create a new reference to your project for Shell32 which is labelled as "Microsoft Shell Controls And Automation" in the references list or can be found at a loction like "C:\WINDOWS\system32\shell32.dll". The coding was a bit undocumented so I've put together this code by trial and error and it may not be fully complete. Please find a code exerpt below which should help you get what you need done.

Code:
Option Explicit

Type FileAttributes
    Name As String
    Size As String
    FileType As String
    DateModified As Date
    DateCreated As Date
    DateAccessed As Date
    Attributes As String
    Status As String
    Owner As String
    Author As String
    Title As String
    Subject As String
    Category As String
End Type

Sub FileAttributesTes()

Dim temp As FileAttributes

    temp = GetFileAttributes("C:\Test.doc")

    MsgBox temp.Owner

End Sub

Public Function GetFileAttributes(strFilePath As String) As FileAttributes

' Shell32 objects
Dim objShell As Shell32.Shell
Dim objFolder As Shell32.Folder
Dim objFolderItem As Shell32.FolderItem

' Other objects
Dim strPath As String
Dim strFileName As String
Dim i As Integer

    ' If the file does not exist then quit out
    If Dir(strFilePath) = "" Then Exit Function

    ' Parse the file name out from the folder path
    strFileName = strFilePath
    i = 1
    Do Until i = 0
        i = InStr(1, strFileName, "\", vbBinaryCompare)
        strFileName = Mid(strFileName, i + 1)
    Loop
    strPath = Left(strFilePath, Len(strFilePath) - Len(strFileName) - 1)

    ' Set up the shell32 Shell object
    Set objShell = New Shell

    ' Set the shell32 folder object
    Set objFolder = objShell.Namespace(strPath)

    ' If we can find the folder then ...
    If (Not objFolder Is Nothing) Then

        ' Set the shell32 file object
        Set objFolderItem = objFolder.ParseName(strFileName)

        ' If we can find the file then get the file attributes
        If (Not objFolderItem Is Nothing) Then

            GetFileAttributes.Name = objFolder.GetDetailsOf(objFolderItem, 0)
            GetFileAttributes.Size = objFolder.GetDetailsOf(objFolderItem, 1)
            GetFileAttributes.FileType = objFolder.GetDetailsOf(objFolderItem, 2)
            GetFileAttributes.DateModified = CDate(objFolder.GetDetailsOf(objFolderItem, 3))
            GetFileAttributes.DateCreated = CDate(objFolder.GetDetailsOf(objFolderItem, 4))
            GetFileAttributes.DateAccessed = CDate(objFolder.GetDetailsOf(objFolderItem, 5))
            GetFileAttributes.Attributes = objFolder.GetDetailsOf(objFolderItem, 6)
            GetFileAttributes.Status = objFolder.GetDetailsOf(objFolderItem, 7)
            GetFileAttributes.Owner = objFolder.GetDetailsOf(objFolderItem, 8)
            GetFileAttributes.Author = objFolder.GetDetailsOf(objFolderItem, 9)
            GetFileAttributes.Title = objFolder.GetDetailsOf(objFolderItem, 10)
            GetFileAttributes.Subject = objFolder.GetDetailsOf(objFolderItem, 11)
            GetFileAttributes.Category = objFolder.GetDetailsOf(objFolderItem, 12)

        End If

        Set objFolderItem = Nothing

    End If

    Set objFolder = Nothing
    Set objShell = Nothing

End Function
Hope this helps,
Maccas
 
Old December 9th, 2005, 07:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I've discovered that you can get the titles of the column numbers by passing the Null character to vItem paramater of the GetDetailsOf method. The full list of the types of info you can get (on my PC) is as follows:

0 - Name
1 - Size
2 - Type
3 - Date Modified
4 - Date Created
5 - Date Accessed
6 - Attributes
7 - Status
8 - Owner
9 - Author
10 - Title
11 - Subject
12 - Category
13 - Pages
14 - Comments
15 - Copyright
16 - Artist
17 - Album Title
18 - Year
19 - Track Number
20 - Genre
21 - Duration
22 - Bit Rate
23 - Protected
24 - Camera Model
25 - Date Picture Taken
26 - Dimensions
27 -
28 -
29 - Episode Name
30 - Program Description
31 -
32 - Audio sample size
33 - Audio sample rate
34 - Channels
35 - Company
36 - Description
37 - File Version
38 - Product Name
39 - Product Version

and I got this by using the following code:

Code:
Sub Test()

' Shell32 objects
Dim objShell As Shell32.Shell
Dim objFolder As Shell32.Folder
Dim objFolderItem As Shell32.FolderItem

' Other objects
Dim strPath As String
Dim i As Integer
Dim strTitles(39) As String

    strPath = "C:\"

    ' Set up the shell32 Shell object
    Set objShell = New Shell

    ' Set the shell32 folder object
    Set objFolder = objShell.Namespace(strPath)

    ' If we can find the folder then ...
    If (Not objFolder Is Nothing) Then

            For i = 0 To 100
                ActiveSheet.Cells(i + 1, 1).Value = i & " - " & objFolder.GetDetailsOf(vbNull, i)
            Next i

    End If

    Set objFolder = Nothing
    Set objShell = Nothing

End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to export registration information asCSV file silu95421 Classic ASP Professional 0 October 27th, 2007 04:52 AM
Append Information to a XML file YoungLuke C# 2 July 26th, 2007 02:15 PM
Get information from text file Hoang2005 Excel VBA 2 February 5th, 2006 09:53 PM
Choose information from text file Hoang2005 Excel VBA 0 January 18th, 2006 05:52 AM
ClassView information file Gert Visual C++ 2 August 4th, 2004 05:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.