How to Play a Sound Note Using Visual Basic for Applications (162550)



The information in this article applies to:

  • Microsoft Excel for Windows 95 7.0a
  • Microsoft Excel for Windows 95
  • Microsoft Excel for Windows 5.0
  • Microsoft Excel for Windows 5.0c
  • Microsoft Excel for the Macintosh 5.0
  • Microsoft Excel for the Macintosh 5.0a

This article was previously published under Q162550

SUMMARY

This article describes how to insert a sound note into a cell and play the sound using a Microsoft Visual Basic for Applications macro procedure in the versions of Microsoft Excel listed above.

NOTE: Microsoft Excel 97 for Windows and Microsoft Excel 98 Macintosh Edition do not support sound notes.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
  1. In a new workbook, click cell A1 on Sheet1 and click Note on the Insert menu.
  2. In the Cell Note dialog box, click Import.
  3. Open a folder that contains a sound (.wav) file to play, and then click OK. The following sound files are typically installed by Windows or the Macintosh operating systems.
          Operating system     Folder               File
          --------------------------------------------------
    
          Windows 3.x          C:\Windows           Ding.wav
          Windows 95           C:\Windows\Media     Ding.wav
          Macintosh            System Briefcase     Quack
    						
  4. In the Cell Note dialog box, click Add, and then click OK.
  5. In a new module sheet, type the following macro:
              ' Before running this macro you must insert a sound note into
          ' cell A1 on sheet1.
    
          Sub PlaySound()
    
             ' Insert a sound note into Cell A1.
             ' Test for sound capability.
             If Application.CanPlaySounds Then
                ' Play the SoundNote in cell A1.
                Worksheets("Sheet1").Range("A1").SoundNote.Play
             End If
          End Sub
    						
  6. To run the macro, click Macro on the Tools menu, select PlaySound, and then click Run.

Modification Type:MinorLast Reviewed:10/10/2006
Keywords:kbcode kbhowto kbProgramming KB162550