Developing with VBA in PowerPoint:mac 2016Bugs, incompatibilities and other things to watch out for
Why create/publish this page? VBA is an ancient technology. I mean over 25 years old. That doesn’t make it bad. In fact, it’s still the ONLY environment a developer can use to create a cross-compatible, PC & Mac, Office application add-in that is tightly integrated with the application’s Object Model.
This is a summary list of things I’ve discovered while developing a cross-compatible VBA application add-in for the Windows and Mac versions of PowerPoint 2016. It’s not intended to be 100% comprehensive and I will add any new findings to the list as and when I come across them. Thanks to PowerPoint MVP Steve Rindsberg of PPTools for helping me validate and report some of these issues.
If you find something incorrect or want to add something, please contact us.
For further Mac VBA tips, Ron de Bruin’s Excel:mac pages are excellent.
Object Model Bugs
ActiveWindow.View.Slide.SlideIndex will raise an error if a slide is selected by its thumbnail in the thumbnail pane. These all work as expected:
- ActiveWindow.View.Type returns ppViewNormal
- ActiveWindow.Selection.Type returns ppSelectionSlides
- ActiveWindow.Panes(1).Active returns True
The workaround is to force the activation of the slide pane e.g If ActiveWindow.View.Type = ppViewNormal Then ActiveWindow.Panes(2).Activate
Selection.HasChildShapeRange always returns False even if there are children selected within a group of objects.
Object Model Incompatibilities
Guides collection not available for Presentation, CustomLayout or SlideMaster objects.
ShapeRange.MergeShapes method not available. Solution is to use CommandBars.ExecuteMso “ShapesCombine” or “ShapesFragment” or “ShapesIntersect” or “ShapesSubtract” or “ShapesUnion”.
Userforms cannot be created, viewed in design mode or edited. They must be designed on PC and then tested on Mac. The code module associated with a userform can be viewed and edited on Mac.
MouseIcon and custom MousePointer properties are not supported. When setting a custom .ico or .cur image on a userform control, PowerPoint Mac will be unable to run any code and will raise the extremely useful error “Microsoft Visual Basic” followed by a second one when attempting to use the Show method “Unexpected error (485)“.
ControlTipText property is ignored.
Modeless forms not supported.
cmd+v pastes the character v into text boxes instead of the content of the clipboard. A workaround using automatic clipboard pasting is available here.
Path separators may use : or / instead of the \ used in Windows.
CustomUI / Fluent UI / Ribbon Bugs
GetShowLabel callback is broken. It only fires when the ribbon is initially loaded and not when the Invalidate method is called. This bug has been reported to and confirmed by Microsoft.
LoadPicture doesn’t work to dynamically load a picture into a form control at runtime and there appears to be no equivalent workaround used on Windows (using APIs) to do this on Mac.
CustomUI / Fluent UI / Ribbon Incompatibilities
Backstage View not supported.
Office:mac 2016 runs in a special secure sandbox. This causes all sorts of development and user challenges when trying to do things that were once easy.
For example, if you want to open a file on Office:mac 2011 you could use MacScript. But now that doesn’t work and AppleScriptTask requires the script file with the command to already exist within the sandboxed area of the Mac file system.
Windows APIs vs. Mac Scripting
Obviously Windows APIs don’t exist on the Mac. The next best thing when you can’t find a way to do something in native VBA is to use AppleScript. Office:mac 2011 used MacScript but this doesn’t work on Office:mac 2016 when accessing the file system due to the sandbox environment. To access the files system the new AppleScriptTask function is used but it has to run a pre-existing .scpt file on the machine rather than a run-time build string.
Use the Mac or MAC_OFFICE_VERSION conditional compilation constants in #If…#Then…#ElseIf.. directives.
#If Mac The #If…#Then…#ElseIf.. conditional compiler directive is stated to work similarly [Ref 1] [Ref 2] to the standard If..Then…Else..ElseIf… directive. Only it doesn’t (although these articles refer to Visual Basic and not VBA). This will not behave as expected as the logical operator isn’t handled:
#If Not Mac Then Debug.Print "Not Mac" ' This line runs on both PC and Mac! #Else Debug.Print "Is Mac" #End If
Note that his isn’t exclusive to the Mac constant. but if you only want to run code on a Windows machine you’ll have to do it like this because there is no Win constant (only Win16, Win32, Win64 as per this MSDN article):
#If Mac Then ' Do nothing #Else ' Do windows stuff #End If
Your macro or application add-in can save and recall settings using SaveSetting and GetSetting. On Windows, this stores values in the registry. On a Mac is saves it in a plain text plist file. The folder location for Office:mac 2016 has changed at least once and [may] be one of these:
/Users/<UserName>/Library/Group Containers/UBF8T346G9.Office/VB Settings/ /Users/<UserName>/Library/Group Containers/UBF8T346G9.Office/Profile Settings/
Using empty strings (“”) as the Default parameter in the GetSetting function will raise an error on Mac.
Responding to events such a selection change or a new presentation being opened is essential if you want to keep the state of the ribbon up to date. None of the “proper” application-level events are available on Mac but you can use some of the legacy pseudo-events as described in our application events article.
Application Add-In Installation
If you’re creating a VBA add-in (.ppam) then you can wrap this up in either an EXE, MSI or VBS installer. There is no equivalent on a Mac and the installation must be made manually, on each individual machine, using the PowerPoint / Tools UI.
Digital Signatures are not supported for macro-enabled project files on Mac.
vbCrLf constant behaves differently. On a PC it inserts a single return, on Mac it inserts two.
CDec not working.
MacScript can open a URL in a browser using open location “http://youpresent.co.uk/” but this doesn’t work on Office 2016. Instead, use MacScript to run the shell command do shell script “open http://youpresent.co.uk/”
ActivePresentation.FollowHyperlink not working (I tried to use this as a workaround for the OpenURL procedure above until I found a new script solution)
SendKeys not working.