PDA

View Full Version : read / display file properties / title



jbr0005
04-14-2010, 12:24 PM
Hello!

I have a code that searches through a folder for filenames that match inputted criteria and generates hyperlinks to those files on my spreadsheet. I want to do the same with the file titles, which are under the file properties? Anyone know how I can read a file's title?

I'm using Excel 2007 and VBA... 2003?

Thanks!

jbr0005
04-14-2010, 12:36 PM
ignore that 2003, I'm not sure which version I'm using. Whatever comes with a purchase of Office 2007.

Tommy
04-14-2010, 01:11 PM
Hi jbr0005,

Welcome to the board!

I found this at MS's web site

Dim arrHeaders(35)
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("C:\Scripts")
For i = 0 to 34
arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
Next
For Each strFileName in objFolder.Items
For i = 0 to 34
Wscript.Echo i & vbtab & arrHeaders(i) _
& ": " & objFolder.GetDetailsOf(strFileName, i)
Next
Next



This is the link
http://technet.microsoft.com/en-us/library/ee176615.aspx

If you need more help just let us know!

jbr0005
04-14-2010, 01:45 PM
I used the prescribed code, but my 'arrHeaders' variable is blank.. I'm not sure if it's responding to the Shell function, because when typing in the '.' they scroll down box that usually pops up, doesn't. Here's what it looks like:

Dim arrHeaders
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(FullPath & "CMT-Shell 1-U34-ND-09-2055.pdf")
arrHeaders = objFolder.GetDetailsOf(objFolder.Items, 0)
MsgBox (arrHeaders)


With a blank message box.

Tommy
04-15-2010, 12:40 PM
This one is not blank. First notice that I did not send the file to the folder object I used a folder (FullPath). The first loop is picking up the available options for the folder. (I have no idea if it changes from folder to folder) Then when I am cycling through the files in that directory I check to see if it is the file I am looking for and if it is I display a message box with the information stored in the file's information.


Sub kk(iFileName As String)
Dim arrHeaders(35)
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(FullPath) 'just the directory
For i = 0 To 34
arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
Next
For Each strFileName In objFolder.Items
If strFileName = iFileName Then
For i = 0 To 34
MsgBox i & vbTab & arrHeaders(i) _
& ": " & objFolder.GetDetailsOf(strFileName, i)
Next
End If
Next
End Sub



EDIT: I Goofed so I fixed it :) Tommy

jbr0005
04-15-2010, 01:06 PM
Thank you so much for the help!!

jbr0005
04-19-2010, 02:01 PM
Any quick pointers on how I could get the file name, not the file title, using this same sequence?

Tommy
04-20-2010, 03:22 PM
For Each strFileName In objFolder.Items
If strFileName = iFileName Then
For i = 0 To 34 '0 will be the file name :) all 35 addressable properties are listed.
MsgBox i & vbTab & arrHeaders(i) _
& ": " & objFolder.GetDetailsOf(strFileName, i)
Next
End If
Next

jbr0005
04-21-2010, 05:43 AM
Of course... I tried all numbers but zero :doh: Thank you Tommy you've been a great help!