Need help to change this code I found to get data information from a folder

dee101

Active Member
Joined
Aug 21, 2004
Messages
282
I found this macro to get some information from files in a folder, the folder I have has pictures in it and I want to get the date the picturs were taken, this is putting in some kind of date but it is not when they were taken.

How would I do that, I am using Excel 2003 if that helps

Thanks







Code:
Sub listfiles()

Dim r As Integer, F As String, Directory As String

Directory = Application.DefaultFilePath _

& "\My Pictures\Old Building And Things\"

r = 1

Cells(r, 1) = "FileName"

Cells(r, 2) = "Size"

Cells(r, 3) = "Date Time"

Range("A1:c1").Font.Bold = True

'Get Directory

F = Dir(Directory) ', 7)

Do While F <> ""

r = r + 1

Cells(r, 1) = F

Cells(r, 2) = FileLen(Directory & F)

Cells(r, 3) = FileDateTime(Directory & F)

'Get next File

F = Dir()

Loop

End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
There's another method here using the Microsoft Windows Image Acquisition Library. (worked on the file you uploaded :) )


VBA Code:
Sub listfiles()

Dim r As Integer, F As String, Directory As String

Set ImgFile = New WIA.ImageFile

Directory = "C:\Users\andrew.marshall\Desktop\"

r = 1

Cells(r, 1) = "FileName"

Cells(r, 2) = "Size"

Cells(r, 3) = "Date Time"

Cells(r, 3) = "Created"

Range("A1:c1").Font.Bold = True

'Get Directory

F = Dir(Directory)

Do While F <> ""

r = r + 1

Cells(r, 1) = F

Cells(r, 2) = FileLen(Directory & F)

Cells(r, 3) = FileDateTime(Directory & F)

ImgFile.LoadFile (Directory & F)

Cells(r, 4) = ImgFile.Properties("ExifDTOrig")

'Get next File

F = Dir()

Loop

End Sub
 
Upvote 0
*Fixed the headings

VBA Code:
Sub listfiles()

Dim r As Integer, F As String, Directory As String

Set ImgFile = New WIA.ImageFile

Directory = Application.DefaultFilePath _

& "\My Pictures\Old Building And Things\"

r = 1

Cells(r, 1) = "FileName"

Cells(r, 2) = "Size"

Cells(r, 3) = "Date Time"

Cells(r, 4) = "Created"

Range("A1:D1").Font.Bold = True

'Get Directory

F = Dir(Directory)

Do While F <> ""

r = r + 1

Cells(r, 1) = F

Cells(r, 2) = FileLen(Directory & F)

Cells(r, 3) = FileDateTime(Directory & F)

ImgFile.LoadFile (Directory & F)

Cells(r, 4) = ImgFile.Properties("ExifDTOrig")

'Get next File

F = Dir()

Loop

End Sub
 
Upvote 0
I'm pulling in this when I save the attachment.

FileNameSizeDate TimeCreated
!1.JPG
225455​
22/02/21 09:05​
2017:11:26 13:34:56

There was another Property that had the same 2017 date (ExifDTDigitized), so try the below.


VBA Code:
Sub listfiles()

Dim r As Integer, F As String, Directory As String

Set ImgFile = New WIA.ImageFile

Directory = Application.DefaultFilePath _

& "\My Pictures\Old Building And Things\"

r = 1

Cells(r, 1) = "FileName"

Cells(r, 2) = "Size"

Cells(r, 3) = "Date Time"

Cells(r, 4) = "Created"

Range("A1:D1").Font.Bold = True

'Get Directory

F = Dir(Directory)

Do While F <> ""

r = r + 1

Cells(r, 1) = F

Cells(r, 2) = FileLen(Directory & F)

Cells(r, 3) = FileDateTime(Directory & F)

ImgFile.LoadFile (Directory & F)

Cells(r, 4) = ImgFile.Properties("ExifDTDigitized")

'Get next File

F = Dir()

Loop

End Sub

If that fails hopefully someone can step in and help here, i've exhausted the methods I could find.
 
Upvote 0
Sorry it took so long to get back to you, been out of town, but I still get the last modified date
 
Upvote 0

Forum statistics

Threads
1,215,497
Messages
6,125,160
Members
449,209
Latest member
BakerSteve

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