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 examples below that only let you select xls, xlsx and xlsm files, and you can also set the start folder and also say if you want to select one or one or more files..

Example for Mac Excel (9-Dec-2024)

Below you will find two example macro's and a function that both macro's use. Both macro's open the Desktop folder in the browse window, you can open the first macro without changing it, because it use MacScript to get the Desktop folder path, in the second macro you must enter the path yourself. In both macro's you can only select xls, xlsx or xlsm files, see the function call in the macro's with the three arguments how to change this for selecting only one file or other file formats. For testing it will show a msgbox with the path of each file you have selected.

Other File formats

In the function call in the macro you see this code part that say which file format you can select, xls, xlsx and xlsm. You see that I add 3 file formats in the examples, but you can change that if you also want to add for example xlsb files.
If you only want one format you can use this to be able to only select xlsx files for example.

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

This is a list of a few formats that you can use :
  • xls : com.microsoft.Excel.xls
  • xlsx : org.openxmlformats.spreadsheetml.sheet
  • xlsm : org.openxmlformats.spreadsheetml.sheet.macroenabled
  • xlsb : com.microsoft.Excel.sheet.binary.macroenabled
  • csv : public.comma-separated-values-text
  • doc : com.microsoft.word.doc
  • docx : org.openxmlformats.wordprocessingml.document
  • docm : org.openxmlformats.wordprocessingml.document.macroenabled
  • ppt : com.microsoft.powerpoint.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 : com.apple.traditional-mac-plain-text
  • htm : public.html
07/03/2025
Web design by Will Woodgate