Results 1 to 9 of 9
  1. #1
    Lounger
    Join Date
    Jan 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Picture Property (VB / VBA 2003)

    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

  2. #2
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Picture Property (VB / VBA 2003)

    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

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Picture Property (VB / VBA 2003)

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

  4. #4
    Lounger
    Join Date
    Jan 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Picture Property (VB / VBA 2003)

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

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Picture Property (VB / VBA 2003)

    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)

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Picture Property (VB / VBA 2003)

    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.

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

  7. #7
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Picture Property (VB / VBA 2003)

    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:
    <pre> Dim objExif as New ExifReader
    Dim txtExifInfo as String

    objExif.Load "C:Path_To_Jpg.jpg"
    txtExifInfo = objExif.Tag(DateTimeOriginal)
    MsgBox txtExifInfo
    </pre>


    Alan
    Attached Files Attached Files

  8. #8
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Picture Property (VB / VBA 2003)

    <img src=/S/hmmn.gif border=0 alt=hmmn width=15 height=15>... I kinda doubt this myself. But I could be wrong of course. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> I'd be interested if you uncover any info.

    Alan

  9. #9
    Lounger
    Join Date
    Jan 2007
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Picture Property (VB / VBA 2003)

    Thanks Hans. The function works great!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •