![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Join Date: May 2002
Posts: 88
|
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 |
|
|
|
|
|
#2 |
|
Join Date: Jul 2002
Location: Salem, OR
Posts: 418
|
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 |
|
|
|
|
|
#3 |
|
Join Date: May 2002
Posts: 88
|
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 |
|
|
|
|
|
#4 |
|
Join Date: May 2002
Posts: 88
|
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 |
|
|
|
|
|
#5 |
|
Join Date: May 2002
Posts: 88
|
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 |
|
|
|
|
|
#6 |
|
Join Date: Jul 2002
Location: Salem, OR
Posts: 418
|
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 |
|
|
|
|
|
#7 |
|
Join Date: May 2002
Posts: 88
|
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 |
|
|
|
|
|
#8 |
|
Join Date: Jul 2002
Location: Salem, OR
Posts: 418
|
Hi, John -
You may also want to check this out: http://groups.google.com/groups?hl=e...el.programming HTH, Golf |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|