I've just created a button on excel that allows me to select a folder and display the name of the files it contains.
Sub extract_IPTC_From_Folder()
On Error GoTo err
Dim fileExplorer As FileDialog
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object
Set fileExplorer = Application.FileDialog(msoFileDialogFolderPicker)
fileExplorer.AllowMultiSelect = False
i = 4
With fileExplorer
If .Show = -1 Then
Set oFSO = CreateObject("Scripting.FileSystemObject")
For Each oFile In oFSO.GetFolder(.SelectedItems.Item(1)).Files
MsgBox oFile.Name
Next oFile
Else
MsgBox "avorted"
[folderPath] = ""
End If
End With
err:
Exit Sub
End Sub
I would like to find a way to extract the IPTC data from each of these jpg files to display them in my excel file but I can't find any way to do that with VBA.
Here is some code you can modify to do that. For example, you might want to restrict to looking only at
*.jpg
files.You will also need to determine the names of the specific IPTC data you wish to extract, however. I included some IPTC data names, but modify to suit.
Note that as of today, on my computer, there are 320 file properties possible in the list. This number, as well as the location of various properties, changes from time to time. I have set fileProps to a ubound of 500, but that might need to be increased in the future (it used to be that 35 was sufficient).
Here is an example of output from a random "pictures" type folder I selected, along with the particular file properties I hard coded in the macro: