'Dir' in Word 2011

Discussion in 'Mac Apps and Mac App Store' started by Pathagoras1953, Aug 22, 2011.

  1. Pathagoras1953 macrumors newbie

    Aug 22, 2011
    Dir in Word2011 does not allow wildcard searches. I can live with that. But I still need to limit my search to something other than the entire folder, and that seems to be provided with the command

    However, there is zero, nada, zilch in the documentation as to what the 'filetype' calls are. I tried to find them on my own with a routine like this:


    but that didn't work.

    Is there a listing or method to determine file types for MacID?
  2. Pathagoras1953, Aug 23, 2011
    Last edited: Aug 23, 2011

    Pathagoras1953 thread starter macrumors newbie

    Aug 22, 2011
    My solution

    Sometimes you end up answering your own question. (Plus I need the credit for posts so I can access the super-dooper-user's part of the forum.)

    Forget the MacID. Of course what I really needed was a way to handle things like '.doc' and '.docx' and '.docm', to get just '.doc' files in some cases and '.doc*' files in others. So I wrote a routine that allows me to search just for a particular extension if no "*" is sent to it, and to search for an 'expanded' list if a "*" is sent. Here is and example of the "call"

    Private Sub GetAllDocs()
        GetFileList PathName, "doc"
        GetFileList PathName, "doc*"
    End Sub
    And here is the actual routine that will be processed:
    Sub GetFileList(folderPath As String, filetype As String)
      'MAC VBA does not support wildcards in DIR function
      'So fake it.
      Dim file As String
      Dim oCollection As New Collection
      folderPath = AddLastSlash(folderPath)
      file = Dir$(folderPath) 'setup initial file
      Do While Len(file)
          If InStr(filetype, "*") Then
              'if a star exists in the call, just look for that text 
              'within the initial characters of the extension 
              '(extension presumed 4 characters max, plus the period)
              If InStr(Right(file, 5), filetype) Then
                  oCollection.Add folderPath & file
              End If
             'if no star in the call, then test if extensions match 
             If Right(file, len(filetype)) = filetype Then
                  oCollection.Add folderPath & file
              End If
          End If
          'read next item
          file = Dir$
     End Sub
    I used a 'collection' to store the filenames, but you can use a list, an array, etc.

    HTH somebody.

Share This Page