Calling AppleScript from Excel using VBA Stalls & Fails

I have been trying to call an AppleScript Routine that works fine if I run it by itself but cannot get it to run if called from Excel using VBA.
This is the AppleScript Routine I have shortened it for testing purposes. the name of the script is “TestCallbyExcel.scpt”



Display Dialog "This sets Safari on the left and Excel on the Right"

my Openapplications() --Test to make sure Exel and Safari are open & positioned next each sheet

on Openapplications()
	--display dialog "in set up screen"
	tell application "Finder"
		--Sets up Safari on the left of the screen and excel onthe right
		set BoundsAll to bounds of window of desktop
		set WinW to item 3 of BoundsAll
		set WinH to item 4 of BoundsAll
	end tell
	--In use it is intented this script will be called from an open Excel WorkBook. Therefore this routine will not fail on the Excel test
	if application "Microsoft Excel" is running then
		tell application "Microsoft Excel" to set the bounds of the front window to {WinW / 2, 22, WinW, WinH - 50}
		if application "Safari" is running then
			--################-
			--Necessary in case Safari running but no window visible
			activate
			tell application "System Events"
				tell process "Safari"
					click menu item "New Window" of menu "File" of menu bar 1
				end tell
			end tell
			--###############
			tell application "Safari" to set the bounds of the front window to {0, 22, WinW / 2, WinH - 50}
		else
			display dialog "Safari Closed so open it"
			tell application "Safari"
				activate
				tell application "Safari" to set the bounds of the front window to {0, 22, WinW / 2, WinH - 50}
			end tell
		end if
	else
		"Excel Closed"
	end if
end Openapplications



The VBA routine that calls it is

When called it displays the dialog box and then hangs and then I get an invalid procedure message and line in VBA starting “MacScript” is highlighted.

Thanks for any suggestions.

What version of Excel are you using? The MacScript function has been deprecated for several years now, mainly because of the sandbox, IIRC. You should use AppleScriptTask instead. But be warned that it’s a pretty crappy solution.

Hi
Still on Excel 2011 because of the lack of user forms in 2016 on a Mac so cannot use AppleScriptTask. However it turns out I was way over complication the problem using “do shell script”.

The following works fine and thank your taking the time to reply.