Excel: SOUND.PLAY() Ignored in Auto_Open Macro

ID: Q90786


The information in this article applies to:
  • Microsoft Excel for the Macintosh, version 4.0
  • Microsoft Excel for Windows, versions 4.0, 4.0a


SUMMARY

In Microsoft Excel version 4.0, a SOUND.PLAY() macro statement in an Auto_Open routine that executes while Microsoft Excel is starting may be ignored or the macro may halt.

If Microsoft Excel is already open when the specified Auto_Open routine is executed, the function behaves normally.


MORE INFORMATION

Auto_Open is a name you define on a worksheet or a macro sheet to refer to a macro that you want to execute each time you open the file. In any case where Microsoft Excel and the file containing the Auto_Open defined name are launched simultaneously, a SOUND.PLAY() statement contained in the executed Auto_Open macro will, under certain conditions, be ignored in Microsoft Excel for the Macintosh and will cause the macro to halt in error in Microsoft Excel for Windows.

Microsoft Excel and a document will be started simultaneously when you have saved the document to the Excel Startup Folder (4) (if you are using Microsoft Excel for the Macintosh) or the XLSTART directory (if you are using Microsoft Excel for Windows). Both documents will also be started simultaneously when you open a document from the Finder (if you are using Microsoft Excel for the Macintosh), or from Program Manager or File Manager (if you are using Microsoft Excel for Windows); in all of these cases, if Microsoft Excel is not already running in the background, it will be started along with the document.

Microsoft Excel for the Macintosh

In Microsoft Excel for the Macintosh, the SOUND.PLAY() statement is ignored when the cell_ref argument is used to reference a cell note containing a sound that you want to play. The statement will execute properly if you use the file_text argument to specify a sound folder. Specifying file_text without a resource argument will play the first sound resource in the folder. If you want a specific sound to play, specify the appropriate sound as the resource argument. Note that the resource argument is only valid on the Macintosh.

Workarounds - Macintosh

There are 3 possible solutions to this problem in Microsoft Excel for the Macintosh:

  • Rather than specifying a cell_ref argument, use the file_text argument with or without an accompanying resource argument. For example:

    =SOUND.PLAY(,"HARD DISK:SOUNDS:SOFT SOUNDS","Chimes")

    -or-


  • Start Microsoft Excel first and then open the file containing the Auto_Open defined name from within the application.

    -or-


  • Use the ON.TIME() function to execute a macro that contains the SOUND.PLAY() function. This allows Microsoft Excel to complete its startup and then execute the SOUND.PLAY() statement. The following macro is an example of this workaround:

    
          A1:  Auto_Open
          A2:  =ON.TIME(NOW(),"PlaySounds")
          A3:  =RETURN()
          A4:
          A5:  PlaySounds
          A6:  =SOUND.PLAY(B1)
          A7:  =RETURN() 


Cell B1 on the macro sheet contains a sound cell note.

Microsoft Excel for Windows

In Microsoft Excel for Windows, specifying the cell_ref argument in the SOUND.PLAY() statement will work correctly when a sheet and Microsoft Excel are launched simultaneously. If, however, the file_text argument is specified, the macro will halt in error at the cell containing the SOUND.PLAY() statement. Note that the resource argument is not valid in Microsoft Excel for Windows.

Workarounds - Windows Operating Environment

There are 3 possible solutions to this problem.

  • Do the following to import the sound into a cell note and use the cell_ref argument rather than the file_text argument:

    1. the Formula menu, Choose Note and choose the Import button.

    2. Select the sound file you want to play and choose the OK button twice.

    In the following example, the cell note is in B1 on the macro sheet.

    =SOUND.PLAY(B1)

    -or-


  • Start Microsoft Excel first and then open the document containing the Auto_Open defined name from within the application.

    -or-




  • Use the ON.TIME() function to execute a macro that contains the SOUND.PLAY() function. This allows Microsoft Excel to complete its startup and then execute the SOUND.PLAY() statement. The following macro is an example:

    
          A1: Auto_Open
          A2: =ON.TIME(NOW(),"PlaySounds")
          A3: =RETURN()
          A4:
          A5: PlaySounds
          A6: =SOUND.PLAY(,"C:\SOUNDS\SOUND.WAV")
          A7: =RETURN() 


    This SOUND.PLAY() statement plays the SOUND.WAV file in the SOUNDS directory.


NOTE: Tolerance, the third argument of the ON.TIME() function, specifies the time the program will wait in order to execute a macro if Excel is not in Ready, Copy, Cut, or Find mode at the precise time specified for macro execution. If this argument is omitted, this amount of time is assumed to be infinite. The result of this is that PlaySounds will run at the next available moment.


REFERENCES

"Function Reference," version 4.0, pages 305-306, 415-416

Additional query words: 4.00a

Keywords :
Version :
Platform :
Issue type :


Last Reviewed: March 29, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.