VBA & Macro Problems

How to Adapt an Excel VBA Picture Macro for Mac

Huda QurayshiHuda Qurayshi Oct 28, 2026 869 views

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.

How to Adapt an Excel VBA Picture Macro for Mac
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA Editor

Launch Excel on your Mac, navigate to the Developer tab, and click on Visual Basic to open the macro editor.

2
Locate File Selection Code

Find the line of code in your macro that uses Application.GetOpenFilename to prompt the user for picture selection.

3
Implement MacScript

Replace the GetOpenFilename line with MacScript("choose folder as string"). This will prompt the user to select an entire folder containing the pictures.

4
Test the Code Separately

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.

Replace GetOpenFilename with MacScript
Tip: Using a folder-selection approach on Mac is often cleaner than trying to force multi-file selection, allowing your macro to simply loop through all images in the chosen directory.
Free Microsoft Office alternative

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. 1. Download WPS Office: Visit the official WPS website and download the free version for your Mac.
  2. 2. Install and Launch: Follow the simple installation prompts and launch the WPS Spreadsheet application.
  3. 3. Open Your Spreadsheets: Open your existing .xlsx or .xls files directly in WPS Office to experience seamless formatting and high compatibility.
Free and lightweight alternative to Microsoft Office.Fully compatible with Microsoft Excel (.xlsx, .xls, .csv) formats.Familiar user interface requiring zero learning curve.Cross-platform support for seamless work on both Windows and Mac.
QA img-9

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.