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 30th, 2004, 08:22 PM   #1
johnpdavey
 
Join Date: May 2002
Posts: 88
Default WAV file to play on opening a worksheet

hi.

I would like to play a small wav file each time a worksheet is opened.

I have a workbook with 16 worksheets in which i have set up an interactive game on the lines of 'who wants to be a millionaire'.

The worksheets represent an intro page then 15 worksheets containing the questions / playing area for the £100, £200 ....£1 million questions.

I have a small wav file called 'new question' which plays the theme music.

I would like the wav file to be part of the workbook so that i can share the game with my colleagues and i would like it to play when the tab for each new question (worksheet) is selected.

I have read several posts on wav files in excel but am sorry to say i didn't understand any of them.
I am a complete novice at vba and have no idea what most of the expressions ment or which to adjust to fit my situation.

Can someone please therefore give me very simple step by step instructions on

1 how to put the wav file into my workbook

2 how to set things up so that it plays each time a worksheet tab is selected.

thank you in advance for your assistance
john
johnpdavey is offline   Reply With Quote
Old Mar 31st, 2004, 04:21 AM   #2
golf4
 
golf4's Avatar
 
Join Date: Jul 2002
Location: Salem, OR
Posts: 418
Default Re: WAV file to play on opening a worksheet

Hi, John:

You may want to check out the following links:

http://www.mrexcel.com/board2/viewto...636&highlight=

http://www.mrexcel.com/board2/viewto...946&highlight=


There are other really good threads on the use of wavs. It depends a lot on whether you want to path the code to the wav or embed them in the spreadsheet itself. Post back if you need help.

HTH,

Golf
golf4 is offline   Reply With Quote
Old Mar 31st, 2004, 08:14 PM   #3
johnpdavey
 
Join Date: May 2002
Posts: 88
Default Re: WAV file to play on opening a worksheet

hi Golf
thank you for your reply

i have managed to place the wav file into a worksheet and play it by assigning the following macro, to an object on that sheet.

'Sheets("Data Sheet").Activate
ActiveSheet.Shapes("Object 1").Select
Selection.Verb Verb:=xlPrimary

i have looked at the code that i think is designed to play the wav file when a worksheet is opened and certain conditions are met but as i dont know what most of the pieces of code mean i am not sure what to change or how

Private Sub Workbook_Open()
If Sheets("Data_Entry_Sheet").Range("A14") = "X" Then
Call PlaySound("C:\My Music\welcome.wav", 0)
Sheets("Data_Entry_Sheet").Activate
Range("A1").Activate
UserForm1.Show
End If
End Sub

i assume i set this up by putting the code in the 'view code' area that is on the menu when i right click on a sheet tab.
i also assume i remove the second line and adjust the 3rd line to call playsound("object 1", 0)
as i dont have a user form i assume i delete that line and the following line .
however the resulting code does not appear to do anything when i click on the sheet1 tab.
any suggestions please
thanks
john
johnpdavey is offline   Reply With Quote
Old Mar 31st, 2004, 08:54 PM   #4
johnpdavey
 
Join Date: May 2002
Posts: 88
Default Re: WAV file to play on opening a worksheet

hi
i think i have solved the problem now with the following code

Sub Worksheet_Activate()
'Sheets("Data Sheet").Activate
ActiveSheet.Shapes("Object 1").Select
Selection.Verb Verb:=xlPrimary
End Sub

thanks for the prompts in the right direction
john
johnpdavey is offline   Reply With Quote
Old Mar 31st, 2004, 09:23 PM   #5
johnpdavey
 
Join Date: May 2002
Posts: 88
Default Re: WAV file to play on opening a worksheet

OK one problem solved and another appears

the code noted above works, with the addition of a final line to select cell A1.

however my workbook is set up over 16 pages, 15 of which are the questions and i have set up the wav file to play when the sheet tab for each question is selected.

sheet 1 is for the instructions and the reset button which runs a macro which deletes all the entries inputted by the user and then sets up new questions for the next game.

when i press the reset button i get the following error message

run time error '214767259 (80004005)
method ' select' of object 'shape' failed.

the debug option takes me to the vba code on the first tab that has the wav file and the line

active sheet shapes ("object 1" ). select

is highlighted in yellow.

any ideas on how to sort this out as i need to reset after each game so that new questions can be selected etc

thanks in advance for your assistance

john
johnpdavey is offline   Reply With Quote
Old Apr 1st, 2004, 06:15 AM   #6
golf4
 
golf4's Avatar
 
Join Date: Jul 2002
Location: Salem, OR
Posts: 418
Default Re: WAV file to play on opening a worksheet

Hi, John -

Just a quick one: it looks as if there is an apostrophe mark at the beginning of the 2nd line of code. Try removing that and running it again.

Anyone have any suggestions?

HTH,

Golf
golf4 is offline   Reply With Quote
Old Apr 1st, 2004, 08:31 PM   #7
johnpdavey
 
Join Date: May 2002
Posts: 88
Default Re: WAV file to play on opening a worksheet

hi Golf
i removed the apostrophe and it made no difference.
i even tried removing the second line of code completely.
the wav file was still played when i clicked on the sheet tab but when i tried to run the reset macro i received the same error message as before and the debug option took me back to a problem in the 3rd line of code.
any other ideas?
thanks
john
johnpdavey is offline   Reply With Quote
Old Apr 2nd, 2004, 12:38 AM   #8
golf4
 
golf4's Avatar
 
Join Date: Jul 2002
Location: Salem, OR
Posts: 418
Default Re: WAV file to play on opening a worksheet

Hi, John -

You may also want to check this out:

http://groups.google.com/groups?hl=e...el.programming

HTH,

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 07:36 AM.


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