I'm developing a VBA program on top of Excel for Mac (rev. 16.19). Because I need more room on the (laptop) screen to display results, I want to hide the ribbon when I open the workbook.
All solutions I've seen so far only work on Windows, not on Mac. I also tried Macscript to do it via Applescript (see below). This script works fine if I run it from scripteditor, but not embedded in VBA.
tell application "System Events" to tell process "Microsoft Excel"
set frontmost to true
keystroke "r" using {command down, option down}
end tell
In VBA it looks like this:
Sub example()
Dim toggleRibbon As String
toggleRibbon = "tell application ""System Events"" to tell process ""Microsoft Excel""" & vbNewLine & _
"set frontmost to true" & vbNewLine & _
"keystroke ""r"" using {command down, option down}" & vbNewLine & _
"end tell"
Debug.Print toggleRibbon 'to check format (use of double quotes, etc.)
MacScript (toggleRibbon)
End Sub
Executing this code gives an error 5 during runtime
Can anyone solve my issue?