0

I have the following code which I use to get date properties of some jpg files. I am trying to have it so I can extract day() month() and year() from this. It works most of the time but on occasion, there are some rogue ? in there. I have tried getproperty1 = Replace(getproperty1, "?", "") however this does not work (and wasnt really expecting it to)

intPos = InStrRev(strFile, "\")
strPath = Left(strFile, intPos)
strName = Mid(strFile, intPos + 1)
''debug.print intPos & " .. " & strPath & " .. " & strName
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(strPath)
Set objFolderItem = objFolder.ParseName(strName)
If Not objFolderItem Is Nothing Then
getproperty1 = objFolder.GetDetailsOf(objFolderItem, n)
If getproperty1 = vbNullString Then
getproperty1 = objFolder.GetDetailsOf(objFolderItem, 4)
End If

I am wanting it to always be readable as a date at least, as I will be passing it all back to a duplicate file (see Rotate a saved image with vba for more of an idea as to what I do with it) using some more code I have modified from Chip Pearson's site (http://www.cpearson.com/excel/FileTimes.htm) to write it back to the file which takes the datetime as Double (so will be running Dateserial()+Timeserial() at that point. There are reasons stopping me passing datetime directly between the two as I sometimes need to make amendments in between the two bits of code)

Community
  • 1
  • 1
bmgh1985
  • 779
  • 1
  • 14
  • 38
  • I should mention, getproperty1 is set to be either the "Date Taken" (n) or if that does not exist, the "Date Created" (4). Date Taken is a variable as it is referenced with a different number in XP (so earlier in the code it checks this and puts in the correct number) – bmgh1985 Apr 04 '14 at 14:00

1 Answers1

0

I have used a character strip function to iterate through each individual character, eliminating anything that isnt a number, ":" or a space, then passed it through DateValue() to get it as a recognisable date format. Works like a charm now!

Function stripChars(chrStrp As String)
   stripChars = ""
   For cnt = 1 To Len(chrStrp)
      tmpChar = Mid(chrStrp, cnt, 1)
      If Val(tmpChar) <> 0 Or tmpChar = "0" Or tmpChar = "/" Or tmpChar = " " Or tmpChar = ":" Then
         stripChars = stripChars & tmpChar
      End If
   Next cnt
   Debug.Print stripChars
   stripChars = DateValue(stripChars)
End Function
bmgh1985
  • 779
  • 1
  • 14
  • 38