How to Adapt an Excel VBA Picture Macro for Mac
Question details
The user needs to modify an Excel VBA macro that inserts pictures so it functions correctly on a Mac, specifically addressing file and folder selection dialogs.

- Product
- Microsoft Excel
- Device & OS
- macOS
- Scenario
- Running a Windows-based VBA macro that uses GetOpenFilename to select and insert multiple pictures on a Mac.
- Observed behavior
- The macro fails or behaves unexpectedly on Mac because Windows-specific file and folder selection methods like GetOpenFilename are not natively compatible without adaptation.
Ensure you have enabled the Developer tab in your Mac Excel ribbon and always duplicate your original Windows VBA workbook before testing new Mac-specific code.
Replace GetOpenFilename with MacScript
Use AppleScript commands via the MacScript function to handle folder and file selection natively on macOS.
Because macOS handles file directories differently than Windows, the standard GetOpenFilename dialog may fail or behave incorrectly. Using MacScript allows your VBA code to call native Mac folder selection dialogs, which is often more reliable for selecting multiple pictures.
Launch Excel on your Mac, navigate to the Developer tab, and click on Visual Basic to open the macro editor.
Find the line of code in your macro that uses Application.GetOpenFilename to prompt the user for picture selection.
Replace the GetOpenFilename line with MacScript("choose folder as string"). This will prompt the user to select an entire folder containing the pictures.
Run this MacScript snippet in a separate test macro to ensure it correctly returns the Mac folder path before integrating it into your main picture-insertion macro.

Modify GetOpenFilename for Mac Compatibility
Adapt the existing GetOpenFilename method using Microsoft's specific guidance for Mac file filters.
Try WPS Office for Seamless Spreadsheet Management
If your VBA macros are causing compatibility headaches across different operating systems, WPS Office provides a free, lightweight, and highly compatible alternative to Microsoft Office. Enjoy a familiar interface and seamless migration without the heavy processing overhead.
- 1. Download WPS Office: Visit the official WPS website and download the free version for your Mac.
- 2. Install and Launch: Follow the simple installation prompts and launch the WPS Spreadsheet application.
- 3. Open Your Spreadsheets: Open your existing .xlsx or .xls files directly in WPS Office to experience seamless formatting and high compatibility.

Frequently Asked Questions
Why does my Excel picture macro work on Windows but not on Mac?
Windows and macOS use completely different file systems and dialog boxes. VBA commands like GetOpenFilename that trigger Windows Explorer dialogs require specific adaptations, different file filters, or alternative commands like MacScript to function correctly on a Mac.
Can I make a single VBA macro that works on both Mac and Windows?
Yes. You can use conditional compilation instructions such as '#If Mac Then' to tell Excel to run Mac-specific code (like MacScript) on macOS and standard Windows code (like GetOpenFilename) on Windows PCs.
How do I select an entire folder of pictures in Mac Excel VBA?
Instead of trying to select multiple individual files, it is often easier on a Mac to use the command MacScript("choose folder as string"). This prompts the user to select a directory, and your macro can then be programmed to loop through all the image files inside that folder.




