Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 31

Thread: Can you play sound via VBA?

  1. #21
    MrExcel MVP phantom1975's Avatar
    Join Date
    Jun 2002
    Location
    Omaha, Nebraska
    Posts
    3,962
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    You can also add the Media Player control. Then simply have:

    MediaPlayer1.Open ("C:Tada.wav")

    How can I use this control to play an embedded object in my worksheet? (i.e. I have a wav file that is a SHAPE on a worksheet.)

    _________________
    Pass on what you have learned. Support this great website by clicking on the sponsor's ads!.

    [ This Message was edited by: phantom1975 on 2002-08-23 00:52 ]

  2. #22
    Board Regular
    Join Date
    Mar 2002
    Posts
    88
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Ivan
    I have put the code into the Declarations part of my code, but the compiler is saying "constants, fixed length strings, arrays, user-defined types and declare statements are not allowed as Public members of object modules" and the "Public" line is highlighted.

    Option Explicit

    Public Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
    (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
    Const SND_SYNC = &H0
    Const SND_ASYNC = &H1
    Const SND_NODEFAULT = &H2
    Const SND_MEMORY = &H4
    Const SND_LOOP = &H8
    Const SND_NOSTOP = &H10

    this is all I have in the (General) (Declarations) section. After this , my code continues with the sub Wavstop() sub-routine. is there another (Declarations) area I should have put it in ? Any ideas how to get past this error.
    Thanks

    Bill

  3. #23
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi Bill, put the code in a STD Module and
    not a Sheet code module ie.
    While in VBA Editor Press Ctrl + R (Project explorer ...right click on the Xlobject select Insert > Module
    Kind Regards,
    Ivan F Moala From the City of Sails

  4. #24
    Board Regular
    Join Date
    Mar 2002
    Posts
    88
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Ivan, that works fine now. thanks for your help.

    If you have the time, could you do me one of your great explanations about the difference between that Declaration area and the code Declaration area. I am trying to learn VBA so if you know of any really good Tutorial sites that goes from novice right through to this level ( and beyond !) I would appreciate the link.
    Thanks again
    Bill

  5. #25
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-08-23 00:27, phantom1975 wrote:
    You can also add the Media Player control. Then simply have:

    MediaPlayer1.Open ("C:Tada.wav")

    How can I use this control to play an embedded object in my worksheet? (i.e. I have a wav file that is a SHAPE on a worksheet.)

    _________________
    Pass on what you have learned. Support this great website by clicking on the sponsor's ads!.

    [ This Message was edited by: phantom1975 on 2002-08-23 00:52 ]
    Mr Walker
    There is no need to use the media player to play this. Just use the shapes OLE default action ie. recording a macro then double clicking on the shape to play it....Just remember the Shape is actually an OLE reference to the Sound file > sound file has default application to Action this. Whilst it is embeded it still has a File reference to your Sound file ie. changing the Original path will not play it! (File name is Linked)
    Kind Regards,
    Ivan F Moala From the City of Sails

  6. #26
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-08-23 03:56, Billm wrote:
    Ivan, that works fine now. thanks for your help.

    If you have the time, could you do me one of your great explanations about the difference between that Declaration area and the code Declaration area. I am trying to learn VBA so if you know of any really good Tutorial sites that goes from novice right through to this level ( and beyond !) I would appreciate the link.
    Thanks again
    Bill
    Hi Bill
    Never tried these BUT

    http://www.add-ins.com/pages
    http://www.vbatutor.com/vbatutor.htm

    Plus any of the MVP sites


    Kind Regards,
    Ivan F Moala From the City of Sails

  7. #27
    MrExcel MVP phantom1975's Avatar
    Join Date
    Jun 2002
    Location
    Omaha, Nebraska
    Posts
    3,962
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    How do I embed a sound file then? For instance, if I reference a sound file that is on MY computer but NOT the user's computer, then an error will occur because VB cannot find the sound file. Instead, I want to have the sound file "attached" to the spreadsheet so that the sound file travels with the spreadsheet file.
    Silly Billy was here....

    ***************** EXCEL/VB NEWBIES ARE MY FAVORITE! *****************

  8. #28
    MrExcel MVP Mark O'Brien's Avatar
    Join Date
    Feb 2002
    Location
    Columbus, OH, USA
    Posts
    3,530
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I'd imagine using "Insert|Object|Create From File" would embed the sound file on your worksheet. I've used this trick many times. (ok, once)

  9. #29
    MrExcel MVP phantom1975's Avatar
    Join Date
    Jun 2002
    Location
    Omaha, Nebraska
    Posts
    3,962
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    That's what I have done too. In order to reference the sound file, you have to refer to it as a SHAPE. According to Ivan's post, the sound file is merely a reference to the file's location on the hard drive instead of embedding the file itself. Is it possible to use this "embedded" file using the MediaPlayer control?
    Silly Billy was here....

    ***************** EXCEL/VB NEWBIES ARE MY FAVORITE! *****************

  10. #30
    MrExcel MVP Ivan F Moala's Avatar
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    4,209
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-08-23 14:30, phantom1975 wrote:
    That's what I have done too. In order to reference the sound file, you have to refer to it as a SHAPE. According to Ivan's post, the sound file is merely a reference to the file's location on the hard drive instead of embedding the file itself. Is it possible to use this "embedded" file using the MediaPlayer control?
    What you have to do is CREATE it as a PACKAGE
    and NOT from a file AND then IMPORT the sound file. You don't need to use the media player to reference the Embedded file.


    Kind Regards,
    Ivan F Moala From the City of Sails

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •