I have a macro-enabled workbook that is used on both Windows & Mac. (Probably 80% of my users are on Mac.) I'm using the lastest version (16.48) of Excel on the Mac (part of Office 365).
I just added a UserForm that I show as vbModeless. When a user presses a button on it, I want the focus to shift back to the ActiveSheet ("Sheet1").
I added a line of code at the end of the button click sub:
AppActivate Excel.ThisWorkbook.Application.Caption
This works perfectly on Windows. On Mac, however, it causes the following error:
Run-time error 5: Invalid procedure call or argument
My first question is, does AppActivate work on the Mac at all? If yes, any ideas why the line of code would be causing an error? Do I need to change anything about it to make it work on the Mac?
Assuming AppActivate doesn't work on the Mac, I have tried to come up with an alternate way of doing the same thing. I tried some AppleScript, like so:
Dim myScript As String
myScript = "tell application " & Chr(34) & "Microsoft Excel" & Chr(34) & Chr(10) & _
"tell worksheet " & Chr(34) & "Sheet1" & Chr(34) & " of active workbook" & Chr(10) & _
"activate" & Chr(10) & _
"end tell" & Chr(10) & _
"end tell"
MacScript (myScript)
To make it easier to read, here is what myScript actually looks like:
tell application "Microsoft Excel"
tell worksheet "Sheet1" of active workbook
activate
end tell
end tell
Unfortunately, this code doesn't set the focus back to the worksheet; it stays on the UserForm. Does anyone know of a way to alter this code to make it set the focus to the worksheet?
Thanks for any help you can offer!