Select files on a Mac (GetOpenFilename)

In Windows we can use for example GetOpenFilename to select files and do what we want with the path results, you can use filefilter to only display the files you want and use MultiSelect to select more than one file. Also it is possible with ChDrive and ChDir to set the folder that is selected when GetOpenFilename opens.

But on a Mac the filefilter is not working and it is not possible to select more than one file. Also ChDir is not working like in Windows to set the folder that will open with GetOpenFilename. But we can use a combination of VBA and Applescript, see the example below that only let you select xlsx files and you can also set the start folder.

Important : The file location can be very important in Mac Excel, read the information on this webpage : Problems with Apple’s sandbox requirements in Mac Office

Example for Mac Excel 2011 and higher

You can run the macro below without changing it, it opens the Desktop in Finder and you can only select one xlsx file, see the code how to change this for selecting more than one file. For testing it will open each file you select and show a msgbox and close it.

Other File formats

In the macro you see this code line that say which file format you can select (xlsx).

FileFormat = "{""org.openxmlformats.spreadsheetml.sheet""}"

If you want more then one format you can use this to be able to also select xls files.

FileFormat = "{""org.openxmlformats.spreadsheetml.sheet"",""""}"

This is a list of a few formats that you can use :
  • xls :
  • xlsx : org.openxmlformats.spreadsheetml.sheet
  • xlsm : org.openxmlformats.spreadsheetml.sheet.macroenabled
  • xlsb :
  • csv : public.comma-separated-values-text
  • doc :
  • docx : org.openxmlformats.wordprocessingml.document
  • docm : org.openxmlformats.wordprocessingml.document.macroenabled
  • ppt :
  • pptx : org.openxmlformats.presentationml.presentation
  • pptm : org.openxmlformats.presentationml.presentation.macroenabled
  • txt : public.plain-text
  • pdf : com.adobe.pdf
  • jpg : public.jpeg
  • png : public.png
  • QIF :
  • htm : public.html
Web design by Will Woodgate