Check if File or Folder exists on Mac

Note : When you use VBA in Mac Excel 2016 or higher that is working with files and folders you will notice that it is possible that it will ask you permission to access the file or folder (Grant File Access Prompt), this is because of Apple’s sandbox requirements.This means that when you want to save/open files or check if it exists with VBA code the first time you will be prompted to allow access on the first attempt to access such a folder or file. If you want to avoid problems like this read this page : Problems with Apple’s sandbox requirements

In Excel 2011 we have problems with long file names when you use VBA Dir or GetAttr on a Mac, 27/28 characters (without the ext) is the maximum(with the extension this is 32 characters).The FSO model is not available in Office for the Mac and many other code on the internet have problems with long file names. But you can call AppleScript with VBA to avoid the problem with long file names in Office 2011. If you want an example for 2011 you can mail me, I not publish it on my website because Excel 2011 is not supported anymore.

In Office 2016 and higher for the Mac they fixed the problem with long file names so we can use VBA Dir now in the 2016 and higher to test if a file or folder exists or you can use the AppleScriptTask examples to do it on this page : https://macexcel.com/examples/setupinfo/applescriptask/

Note: In the 4 macro examples below the macros call the FileOrFolderExistsOnYourMac function to test if a file or folder exists on your Mac Desktop.
23/03/2024
Web design by Will Woodgate