title: VBA - get all file properties
body: <p>I want to get properties from all files in a folder. I have this already working for a fixed number of properties, my only concern is to find the last property's index, used in <code>GetDetailsOf</code> method, so that I can have all properties listed.</p>
  
  <p>Function below returns count of properties, but is incorrect, because it's based on last non-empty property name. There are however a few indices with empty names (not sure if they can have values), followed by another indices which have property name with normal string.</p>
  
  <p>I also tried <code>On Error Resume Next</code> with error indicating that last index has already been used, but there never was an error and it resulted in an endless loop, apparently <code>GetDetailsOf</code> will accept every long >=0.</p>
  
  <p>I would also like to know if the number of file properties is the same for each folder on one machine.</p>
  
  <p>EDIT: I may have not clearly expressed it, what I want is to get index of last property name, so that I can check values for all existing properties.</p>
  
  <p>EDIT 2: Here's a link to my file, listing properties for all files in selected folder and subfolders of all levels. There may be some not handled bugs (I already sorted one with shortcuts crashing macro), Windows path length limit comes to my mind, but it will in general work for selected folder.</p>
  
  <p>Main function of interest is CountProperties in list_properties module. It decides on how many property columns will be returned.</p>
  
  <p><a href="https://drive.google.com/open?id=1TRIZJoGnHXs9LJtxDBj9rp27ngkects-" rel="nofollow noreferrer">https://drive.google.com/open?id=1TRIZJoGnHXs9LJtxDBj9rp27ngkects-</a></p>
  
  <pre><code>Function CountProperties(ByRef FldPath) As Long
  
  Dim objShell As Object
  Dim objFolder As Object
  Dim testStr As String
  Dim propertyCnt As Long
  
  Set objShell = CreateObject("Shell.Application")
  Set objFolder = objShell.Namespace(Left(FldPath, Len(FldPath) - 1)) 'no slash in the end
  
  Do
      testStr = vbNullString      
      testStr = objFolder.GetDetailsOf(objFolder.Items, propertyCnt)      
      If testStr = vbNullString Then Exit Do
      propertyCnt = propertyCnt + 1
  Loop
  
  CountProperties = propertyCnt
  
  End Function
  </code></pre>