MrExcel Message Board


Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 18th, 2004, 04:08 AM   #1
golf4
 
golf4's Avatar
 
Join Date: Jul 2002
Location: Salem, OR
Posts: 418
Default Use of Wav Files with a Spreadsheet

Hi, again, everyone -

Just a quick question regarding the use of wav files within a spreadsheet project. I went ahead and borrowed --- yea, that's it: BORROWED --- some code that allows me to tie wavs files to certain actions taken by the user(s) of my spreadsheet. The code below is set to play the wav file called "Rickmeid" when the user enters an "X" in cell H20 of the Data_Entry_Sheet:

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("H20")) Is Nothing Then
Exit Sub
Else

If Intersect(Target, Range("H20")) = "X" Then

Call PlaySound("H:\rickmeid.wav", 0)

End If
End If
End Sub


I was hoping someone could provide me a little help in [1] relocating the wav file into the spreadsheet sheet called WAVS from the user's network (H) drive and [2] how I would modify the code to active the wav file from the WAVS sheet instead of from the user's network (H) drive. I could, probably, locate the wav(s) on the user's C drive, but would rather have the wavs in the spreadsheet itself.

Any assistance you can provide would be great.

Thanks again,

Golf
golf4 is offline   Reply With Quote
Old Mar 18th, 2004, 04:37 AM   #2
DRJ
MrExcel MVP
 
DRJ's Avatar
 
Join Date: Feb 2002
Location: California
Posts: 3,857
Default

First insert the wav file

Insert | Object | From File

Then use this to play it

Code:
ActiveSheet.Shapes("Object 1").Select
Selection.Verb Verb:=xlPrimary
__________________
Excel VBA Training and Certification (Lesson 1 is free)
<hr>

<hr>-Jacob
DRJ is offline   Reply With Quote
Old Mar 18th, 2004, 04:53 AM   #3
golf4
 
golf4's Avatar
 
Join Date: Jul 2002
Location: Salem, OR
Posts: 418
Default Re: Use of Wav Files with a Spreadsheet

Thanks for the response, Jacob -

Just a clarification - using your suggestion, would my code by modified as follows:

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("H20")) Is Nothing Then
Exit Sub
Else

If Intersect(Target, Range("H20")) = "X" Then

ActiveSheet.Shapes("rickmeid.wav").Select
Selection.Verb Verb:=xlPrimary

End If
End If
End Sub


Is this correct?

Thanks
golf4 is offline   Reply With Quote
Old Mar 18th, 2004, 05:00 AM   #4
DRJ
MrExcel MVP
 
DRJ's Avatar
 
Join Date: Feb 2002
Location: California
Posts: 3,857
Default

It should work fine. You can change your code to this though:
Code:
Private Sub Worksheet_Change(ByVal Target As Range) 

    If Not Intersect(Target, Range("H20")) Is Nothing And Intersect(Target, Range("H20")) = "X" Then
        ActiveSheet.Shapes("rickmeid.wav").Select 
        Selection.Verb Verb:=xlPrimary 
        Else
    End If

End Sub
__________________
Excel VBA Training and Certification (Lesson 1 is free)
<hr>

<hr>-Jacob
DRJ is offline   Reply With Quote
Old Mar 18th, 2004, 05:11 AM   #5
golf4
 
golf4's Avatar
 
Join Date: Jul 2002
Location: Salem, OR
Posts: 418
Default Re: Use of Wav Files with a Spreadsheet

Hi, Jacob -

I tried your suggested code replacement, and received the following run-time error:

"Run-Time Error '-2147024809 (80070057) The item with the specified name wasn't found".

I did the Insert - Object - From File and placed it on the WAVS sheet. Does it have to be inserted on the Data_Entry_Sheet?

Thanks
golf4 is offline   Reply With Quote
Old Mar 18th, 2004, 05:20 AM   #6
DRJ
MrExcel MVP
 
DRJ's Avatar
 
Join Date: Feb 2002
Location: California
Posts: 3,857
Default

You need to put the wav file on the active sheet. Or activate the sheet that it is on for the code to work.
__________________
Excel VBA Training and Certification (Lesson 1 is free)
<hr>

<hr>-Jacob
DRJ is offline   Reply With Quote
Old Mar 18th, 2004, 05:35 AM   #7
DRJ
MrExcel MVP
 
DRJ's Avatar
 
Join Date: Feb 2002
Location: California
Posts: 3,857
Default

Just put the file on the data entry sheet and format it with no lines and no fill and it will be invisible, then just stick it somewhere way out of the way.
__________________
Excel VBA Training and Certification (Lesson 1 is free)
<hr>

<hr>-Jacob
DRJ is offline   Reply With Quote
Old Mar 18th, 2004, 05:40 AM   #8
golf4
 
golf4's Avatar
 
Join Date: Jul 2002
Location: Salem, OR
Posts: 418
Default Re: Use of Wav Files with a Spreadsheet

Hi, Jacob -

Ya know: I looked at the :Name" field in the upper left hand corner of the WAVS worksheet and noticed that the wav file was named "Object 3". I tried inserting "Object 3" instead of the wav name and received a different run time error:

"Run Time Error '438': Object doesn't support this property or method".

...... drivin me insane!!!

Thanks
golf4 is offline   Reply With Quote
Old Mar 18th, 2004, 05:47 AM   #9
DRJ
MrExcel MVP
 
DRJ's Avatar
 
Join Date: Feb 2002
Location: California
Posts: 3,857
Default

Make sure the sheet that it is on is active

Sheets("Data Sheet").Activate
ActiveSheet.Shapes("Object 3").Select
Selection.Verb Verb:=xlPrimary
__________________
Excel VBA Training and Certification (Lesson 1 is free)
<hr>

<hr>-Jacob
DRJ is offline   Reply With Quote
Old Mar 18th, 2004, 06:38 AM   #10
golf4
 
golf4's Avatar
 
Join Date: Jul 2002
Location: Salem, OR
Posts: 418
Default Re: Use of Wav Files with a Spreadsheet

Hi, Jacob -

FINALLY!!!!! I was able to get it to work....

I removed the lines and the file, but the "little speaker icon" remains. I can figure out how to hide it (maybe under a clear textbox) because I want to have Data_Entry_Sheet protected and the wav file won't work if both the sheet and wav file is locked. THE FUN NEVER STOPS!!!

Thanks so much for the help,

Golf
golf4 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT +1. The time now is 09:22 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
All contents Copyright 1998-2009 by MrExcel Consulting.