Zach
Zach

Reputation: 347

How to extract exif data from shape using vba Excel 2010?

The project I'm working on imports images from a blob in a MySQL database. Sometimes these images are rotated 90 degrees and the user needs to manually rotate them to the correct orientation.

So my question is, is anyone aware of a function that extract exif data from a shape in Excel using vba? I'm trying to avoid any third party applications to do this.

Upvotes: 2

Views: 1765

Answers (1)

Zach
Zach

Reputation: 347

I eventually turned something up in the bowels of social.msdn.microsoft.com.

Here is the solution. Microsoft Shell Controls and Automation reference required. Credit to OssieMac on social.msdn.microsoft.com. Link to page of post

Pointing it at a shape doesn't seem to work (gives me an error), but I save my mysql blob to a temp file on the pc anyway so this works out for me anyway.

Sub ListMetadata()

Dim fileFolder As String
Dim fileName As String
Dim objShell As Shell32.Shell
Dim objFolder As Shell32.Folder
Dim objItem As Shell32.FolderItem
Dim i As Long

'Edit following line to your path. (Note NO back slash on end.)
fileFolder = ThisWorkbook.Path & "\Picture Test"

'Can insert path like following if you prefer.
'fileFolder = "C:\Users\OssieMac\Documents\Excel\Test Macros\Picture Test"

'Edit following line to your file name
fileName = "DSC00093.JPG"

Set objShell = New Shell
Set objFolder = objShell.Namespace(fileFolder)
Set objItem = objFolder.ParseName(fileName)

With objFolder
  For i = 1 To 1000
    Sheets("Sheet1").Cells(i, "A") = .GetDetailsOf(objItem.Name, i)
    Sheets("Sheet1").Cells(i, "B") = .GetDetailsOf(objItem, i)
  Next i
End With

Set objItem = Nothing
Set objFolder = Nothing
Set objShell = Nothing

End Sub

Upvotes: 2

Related Questions