Properties of a jpg

  • Thread starter Michael Singmin
  • Start date
M

Michael Singmin

Hello Group,

Can one use VBA to extract certain properties of a jpg file that have
been added from Xp Explorer ?

I have collected tons of fine art images from web museums and I have
used the comment field in Explorer to record the year. While in
Explorer, I can easily sort the images in chronologiocal order.

I can display the art in Excel easily and I would like to extract any
information I place in the jpg.

Thanks,

Michael Singmin
 
M

Michel Pierron

Hi Michael,
You can try:

Sub TestExample()
MsgBox JpgComment("c:\MyFile.jpg")
End Sub

Private Function JpgComment$(sFile$)
With CreateObject("Shell.Application") _
..NameSpace(Left$(sFile, lPosition(sFile, "\") - 1))
JpgComment = .GetDetailsOf(.ParseName(Dir$(sFile)), 14)
End With
End Function

Private Function lPosition%(Chain$, Char$)
Dim iPos%
Do
iPos = InStr(lPosition + 1, Chain, Char, 1)
If iPos Then lPosition = iPos Else Exit Do
Loop
End Function

Regards,
MP
 
M

Michael Singmin

Greetings Michel,

Your code is amazing and I have more questions.
How do I access values in other properties of the jpg ?
Eg. I use the Subject field to hold the art genre.

Looking at your code, does this imply one can also add information
into a jpg using VBA ?

Would you care to explain what is happening in your code ?
Is there a jpg document on the Net that documents that structure
of a jpg and how one accesses these values ?

Thanks,

Michael Singmin

=============================================================
 
M

Michel Pierron

Hi Michael,
If you only wish to obtain information of the Subject and Comments fields,
you can modify the JpgComment procedure as follows:

Private Function JpgComment$(sFile$)
With CreateObject("Shell.Application") _
..NameSpace(Left$(sFile, lPosition(sFile, "\") - 1))
JpgComment = .GetDetailsOf(.Items, 11) & ": " _
& .GetDetailsOf(.ParseName(Dir$(sFile)), 11) _
& vbLf & .GetDetailsOf(.Items, 14) & ": " _
& .GetDetailsOf(.ParseName(Dir$(sFile)), 14)
End With
End Function


If you wish to obtain existing information for the whole of the headings,
you can proceed as follows:

Sub TestExample()
MsgBox FileInfo("c:\YourFile.jpg")
End Sub

Private Function FileInfo$(sFile$)
Dim i%, T$
With CreateObject("Shell.Application") _
..NameSpace(Left$(sFile, lPosition(sFile, "\") - 1))
For i = 0 To 34
T = .GetDetailsOf(.ParseName(Dir$(sFile)), i)
If Len(T) Then
If i Then FileInfo = FileInfo & vbLf
FileInfo = FileInfo & .GetDetailsOf(.Items, i) & ": " & T
End If
Next i
End With
End Function

Private Function lPosition%(Chain$, Char$)
Dim iPos%
Do
iPos = InStr(lPosition + 1, Chain, Char, 1)
If iPos Then lPosition = iPos Else Exit Do
Loop
End Function


With vba, if you wish to write your own information, it is much more
complicated because you must know the heading structure of the file.

Regards,
MP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top