VBA to rename picture files based on date taken

roc_on_the_rocks

Board Regular
Joined
Jun 6, 2009
Messages
175
Office Version
  1. 365
Platform
  1. Windows
Hello guys,
I'm taking the Christmas break to organize my 'digital life' and the biggest chunk of it are photos (and videos) files, ten thousands of them, in hundreds of folders.

The problem is that most of these photo files are named like 'IMG_xxxx.jpg'.

I'm looking for a macro that would scan the files in a given folder and would:
1) Rename the photo files with a naming format like this: YYYYMMDD_HHMMSS, based on 'Date Taken' from the EXIF metadata. Skip file if 'Date Taken' is unavailable (like in video files).
2) Create and save an Excel file (it can be csv) in that given folder, with columns listing the original file names and new names.

Of course #1 is more important, #2 is a 'nice to have'.

Do anyone have something like this?

Thanks a million guys! Great to be back here.
 
Managed to replicate the problem; if you Copy/Paste the code of the class module GPSExifReader instead of Importing the originale file created by Wayne Phillips there will be some differences. I think that in the code there are 'special' characters that the CMS or Http doesn't detect.
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
PS. I should've said: "I too think that ..."
Hi all

I have a lot photos that need to be sorted and this sounds like the solution I've been looking for, but I don't want to copy\ paste it if it's not going to work.

So to ask the next logical question, where can we download the original GPSExifReader file created by Wayne Phillips? A search here and a google search didn't give me much pleasure.

Cheers
Chris
 
Upvote 0
You can retreive the modules from this LINK; download "EXIFReader", it's a zipped file of an Access mdb, open its vba and move the 3 modules to your Excel file.
 
Upvote 0
Hi all,

For anyone who stumbles across this thread, and experiences similar difficulties to those expressed above (though I note that a link to the files has been provided), I suspect the issue here is because the VB_PredeclareId attribute of the key class module GPSExifReader has been set to True.

What does this mean?
Ordinarily, when you use class modules, you need to Dim (and Set) them. For example,

VBA Code:
Dim ContactDetails As clsContactDetails
Set ContactDetails = New clsContactDetails
ContactDetails.FirstName = "Dan"
ContactDetails.Hobbies = "Excel"     ' :-)
...
and so on.

However, when the PreDeclareId attribute for a class module is set to True, it doesn't need to be initialised before the public methods and properties can be accessed directly from other modules. That is the case here with GPSExifReader:
VBA Code:
            With GPSExifReader.OpenFile(fl.path)

How do you check the PreDeclareId Attribute of a class module?
You need to export the class module and check the header attribute information. The content of the class module itself will not change, except for the import/export header section (see below). When you do export the class module, you will see the first few lines look like the code snippet below. Line 8 reveals the VB_PreDeclareID attribute:

VBA Code:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "GPSExifReader"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

How do you set it yourself?
If you don't have access to preset file, then you can easily set the attribute yourself by first exporting the class module, changing the attribute value to True, saving the file, and then importing the file back into your project. I suggest that when you export the class module that you remove it at the same time, otherwise when you import the amended class module file, you'll find yourself with multiple copies of the class module!

This came up recently, in fact, here - the code would not work until the class module (including the attribute information) had been imported (rather than copied and pasted) into the VBA Project.

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,547
Members
449,089
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top