I would like to be able to play.wav files repeatedly from within Excel as part of an application I am developing. Users of my VBA application would likely use Excel 2007 and Excel 2010, and possibly Excel 2003. They could be using anything from Windows XP to Vista to Windows 7.
To simplify the distribution of my application, I want to be able to use embedded .wav files rather than reference separate .wav files stored apart from the Excel file. Because of this, I don’t think the approach of using sndPlaySound32 / winmm.dll will work. Is there any way to use those with an embedded .wav file?
If I use the approach of inserting the .wav file as an object, I think the user’s default media player for the .wav file gets opened when I play the file using the “Selection.Verb Verb:= xlPrimary” approach. I think my users will find this distracting to switch between Excel and Windows Media Player, for example. Is there any way that I can tell Excel to not pop up the media player but to instead leave it minimized or in the background?
I have looked at inserting the ActiveX control for Windows Media Player directly into the worksheet, but I can’t understand how I could get it to play a sound file that is embedded directly in the worksheet instead of using a URL to reference a stand-alone file. I think this issue of not being able to access embedded .wav files also applies if I insert the ActiveX control into a form and not directly into the worksheet. Am I correct that the ActiveX Windows Media Player control cannot refer to an embedded file?
I thought maybe I could insert PowerPoint file objects that automatically play sounds as part of the presentation when I selected the embedded object and then call “Selection.Verb Verb:= xlPrimary”. This works, but a presentation window pops up on the screen (although for my purposes it seems less annoying than WMP), and I can only play the sound file once from Excel unless the user closes the presentation after each playing of the sound. I then tried copying the sound file object, calling “Selection.Verb Verb:= xlPrimary” to play the copy, and then using “AppActivate ThisWorkbook.Name” to switch back to Excel. This approach is deficient because every time I call the object to be played, another instance (is that the right term?) of the presentation gets left open (e.g., when I look in the Windows task bar, I see multiple entries for “PowerPoint Slide Show – [Presentation in Sheet1]”).
It would be nice if there was a way to close the instance of the PowerPoint presentation after every time its sound file plays, but I can’t figure out how to do that. I thought maybe I could embed a macro-enabled PowerPoint slide that would auto-close, but I think the relevant events won’t fire unless the user manually calls a PowerPoint macro to initialize the application object every time the PowerPoint instance is created. I don’t want to kill off the entire POWERPNT.EXE process, because the user may have other unsaved PowerPoint files open. When I call “Selection.Verb Verb:= xlPrimary”, is there a way I can get a pointer to the created instance so that I can later selectively close it? Or can I somehow communicate with the PowerPoint process after the sound has been played to close any windows or instances that are partially identified as “[Presentation in Sheet1]”?
I have seen approaches where Excel VBA code creates new slides and then does manipulations via a reference to it. Maybe I could copy the embedded sound file from Excel and paste it into a dynamically created PowerPoint slide, set a property to make it auto-play, and then close the presentation?
Thank you for your help!
To simplify the distribution of my application, I want to be able to use embedded .wav files rather than reference separate .wav files stored apart from the Excel file. Because of this, I don’t think the approach of using sndPlaySound32 / winmm.dll will work. Is there any way to use those with an embedded .wav file?
If I use the approach of inserting the .wav file as an object, I think the user’s default media player for the .wav file gets opened when I play the file using the “Selection.Verb Verb:= xlPrimary” approach. I think my users will find this distracting to switch between Excel and Windows Media Player, for example. Is there any way that I can tell Excel to not pop up the media player but to instead leave it minimized or in the background?
I have looked at inserting the ActiveX control for Windows Media Player directly into the worksheet, but I can’t understand how I could get it to play a sound file that is embedded directly in the worksheet instead of using a URL to reference a stand-alone file. I think this issue of not being able to access embedded .wav files also applies if I insert the ActiveX control into a form and not directly into the worksheet. Am I correct that the ActiveX Windows Media Player control cannot refer to an embedded file?
I thought maybe I could insert PowerPoint file objects that automatically play sounds as part of the presentation when I selected the embedded object and then call “Selection.Verb Verb:= xlPrimary”. This works, but a presentation window pops up on the screen (although for my purposes it seems less annoying than WMP), and I can only play the sound file once from Excel unless the user closes the presentation after each playing of the sound. I then tried copying the sound file object, calling “Selection.Verb Verb:= xlPrimary” to play the copy, and then using “AppActivate ThisWorkbook.Name” to switch back to Excel. This approach is deficient because every time I call the object to be played, another instance (is that the right term?) of the presentation gets left open (e.g., when I look in the Windows task bar, I see multiple entries for “PowerPoint Slide Show – [Presentation in Sheet1]”).
It would be nice if there was a way to close the instance of the PowerPoint presentation after every time its sound file plays, but I can’t figure out how to do that. I thought maybe I could embed a macro-enabled PowerPoint slide that would auto-close, but I think the relevant events won’t fire unless the user manually calls a PowerPoint macro to initialize the application object every time the PowerPoint instance is created. I don’t want to kill off the entire POWERPNT.EXE process, because the user may have other unsaved PowerPoint files open. When I call “Selection.Verb Verb:= xlPrimary”, is there a way I can get a pointer to the created instance so that I can later selectively close it? Or can I somehow communicate with the PowerPoint process after the sound has been played to close any windows or instances that are partially identified as “[Presentation in Sheet1]”?
I have seen approaches where Excel VBA code creates new slides and then does manipulations via a reference to it. Maybe I could copy the embedded sound file from Excel and paste it into a dynamically created PowerPoint slide, set a property to make it auto-play, and then close the presentation?
Thank you for your help!