PDA

View Full Version : Modeless VBA/AppleScript routine - Puzzling



mikerickson
10-28-2008, 01:08 AM
I am confused.
I am having Excel play sounds by running Apple Scripts via the VBA MacScript function. (And learning AppleScript in the process.) This is a minor upgrade from http://vbaexpress.com/forum/showthread.php?t=23121

This is the VB code I'm using
Rem get the filepath to the sound file
uiFilePath = scriptGetFile
If uiFilePath = "False" Then Exit Sub: Rem Cancel pressed

Rem open that file in QuickTime Player
MacScript (scriptOpenFileStr(uiFilePath))

Rem make Excel active
MacScript (scriptActivateExcelStr)

Rem play the file
MacScript (scriptPlaySoundStr):Rem weirdness here
MsgBox "Done playing"

Rem close the file
MacScript (scriptCloseFileStr)


And this is the script that scriptPlaySoundStr generates


tell application "QuickTime Player"
set myVar to name of window 1 of application "QuickTime Player"
play document myVar
End tell
Tell application "Microsoft Excel"
activate
End tell
tell application "QuickTime Player"
repeat while playing of document myVar
end repeat
End tell

Note the loop in the script that repeats until the song is finished.

As expected, the MsgBox "Done Playing" does not appear until after the sound is finished.

But I find that I can still use Excel while the song is playing.
I can:
Enter text and formulas into cells (the formulas calculate)
Run Macros (adjusting column widths)
Open a new workbook
Save the workbook that called the sound routine
(i.e. the workbook that is waiting to show "Done Playing")

all while the song is playing.

Can anyone explain what is going on here.
I can understand that QuickTime Player can run at the same time as Excel, but I can't understand why I can do all those things in Excel, while the VBA execution simultaneously hangs, waiting for the line MacScript (scriptPlaySoundStr) to complete.

I think I may be on the track of a modeless Userform for Excel 2004.

I'm cross-posting this on an AppleScript board to check things from that end.
http://bbs.macscripter.net/viewtopic.php?pid=106260#p106260
(http://bbs.macscripter.net/viewtopic.php?pid=106260#p106260)
(MacBook OS10.5 Excel2004)