• Picture Property (VB / VBA 2003)

    Author
    Topic
    #446946

    How can I use VBA to retrieve the picture property “Date Picture Taken”

    I am able to use the FileSystemObject library to retrieve the the following properties:

    “Date Created”
    “Date LastModified”
    “Date LastAccessed”

    Thanks

    Viewing 3 reply threads
    Author
    Replies
    • #1088111

      I don’t know if FSO has (direct) access to this property. It’s part of the EXIF data embedded in the JPEG header information. You could try to programatically parse through the header, but it’s probably easier to use a free command line tool like ExifTool by Phil Harvey. Get the version that DOES NOT require Perl to be installed. There’s a bit of a learning curve on the subject of EXIF tags, pretty well covered on this site, but worth pursuing if you’re going to be working with digital photos.

      Alan

      • #1088112

        No, FSO only has access to the “standard” file properties such as last modified date, not to the JPG-specific EXIF data.

      • #1088113

        I’m sure windows has a com object to be referenced in VBA and retrieve this information. I just can’t find it yet.

        • #1088192

          hmmn… I kinda doubt this myself. But I could be wrong of course. grin I’d be interested if you uncover any info.

          Alan

    • #1088114

      Here is a function you can use to retrieve extended properties of a file:

      Function GetProperty(strFile, n)
      Dim objShell
      Dim objFolder
      Dim objFolderItem
      Dim i
      Dim strPath
      Dim strName
      Dim intPos

      On Error GoTo ErrHandler

      intPos = InStrRev(strFile, “”)
      strPath = Left(strFile, intPos)
      strName = Mid(strFile, intPos + 1)
      Set objShell = CreateObject(“Shell.Application”)
      Set objFolder = objShell.Namespace(strPath)
      Set objFolderItem = objFolder.ParseName(strName)
      If Not objFolderItem Is Nothing Then
      GetProperty = objFolder.GetDetailsOf(objFolderItem, n)
      End If

      ExitHandler:
      Set objFolderItem = Nothing
      Set objFolder = Nothing
      Set objShell = Nothing
      Exit Function

      ErrHandler:
      MsgBox Err.Description, vbExclamation
      Resume ExitHandler
      End Function

      The date a picture was taken happens to be property #25, so you can use

      Debug.Print GetProperty(“C:PicturesMyHouse.jpg”, 25)

    • #1088132

      And here is a list of the values for n you can use in the function from my previous reply. Obviously, not all properties will be filled for all files (16-22 are for MP3 files, 24-26 for JPG files). Properties 27-29 may be used for custom purposes.

      0 Name
      1 Size
      2 Type
      3 Date Modified
      4 Date Created
      5 Date Accessed
      6 Attributes
      7 Status
      8 Owner
      9 Author
      10 Title
      11 Subject
      12 Category
      13 Pages
      14 Comments
      15 Copyright
      16 Artist
      17 Album Title
      18 Year
      19 Track Number
      20 Genre
      21 Duration
      22 Bit Rate
      23 Protected
      24 Camera Model
      25 Date Picture Taken
      26 Dimensions
      27 (Not used)
      28 (Not used)
      29 (Not used)
      30 Company
      31 Description
      32 File Version
      33 Product Name
      34 Product Version
    • #1088133

      In addition to Hans’s neat code, I remembered I had a class/dll for VB6 that allows you to pass a file name and return an object which contains all Exif tags in a JPEG file. Below is an example using this class in VB6:

      	Dim objExif as New ExifReader
      	Dim txtExifInfo as String
      	
      	objExif.Load "C:Path_To_Jpg.jpg"
      	txtExifInfo = objExif.Tag(DateTimeOriginal)
      	MsgBox txtExifInfo
      

      Alan

    Viewing 3 reply threads
    Reply To: Picture Property (VB / VBA 2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: