Hi,
i added *.wav to excel file and want to play when condition is met in cell A1.
It is possible directly use object from Excel?
Can you help with code?Screenshot_12.png
Best,
Jacek
Hi,
i added *.wav to excel file and want to play when condition is met in cell A1.
It is possible directly use object from Excel?
Can you help with code?Screenshot_12.png
Best,
Jacek
.
This macro plays the Windows sound TADA, when a cell in the noted range changes :
You should be able to edit this line for your purpose of cell A1 :Please Login or Register to view this content.
Please Login or Register to view this content.
Since I don't know what value you are looking for in A1, here is a suggestion for the code :
Please Login or Register to view this content.
thank you very much!
Problem is that i want to add my own sound into workbook.
Best,
Jacek
.
Change the path of sound file as shown in the macro. Just make certain it is a WAV file.
PlaySoundA "C:\Users\MyComputer\Desktop\ThisIsMyWavFile.wav", 0&, &H20001
PlaySoundA "C:\WavFile\ThisIsMyWavFile.wav", 0&, &H20001
PlaySoundA "D:\SoundsForMyExcelWorkbooks\ThisIsMyWavFile.wav", 0&, &H20001
Hi Logit,
thank you.
But you are using files which you have on disc. I want to add file directly to workbook and use it in every computer.
So somehow save embedded file into disc and read from it.
Best,
Jacek
Ok Guys,
i found very strange code to achieve this.
This is converting wav file to Long to and read this directly in workbook.
Code is from here:
http://www.vbaexpress.com/forum/show...workbook-opens
Best,
Jacek
I fixed the issues.
I am attaching maybe can be useful for you friends.
Best wishes,
Jacek
If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
Ali
Enthusiastic self-taught user of MS Excel who's always learning!
Don't forget to say "thank you" in your thread to anyone who has offered you help.
You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.
Forum Rules (updated August 2023): please read them here.
Not yet,
maybe other people have better solution for this.
Code is very big and not nice (using embedde object to play sound) so i am still open to other answers.
Jacek
Then saying this was VERY misleading:
I fixed the issues.
I am attaching maybe can be useful for you friends.
Sorry,
but i fixed the issues.
But i am always trying to get the best possible solution. Here - i am not sure, maybe there is an other way to do this.
Best,
Jacek
.
jaryszek
Let me know if the sound file in the attached plays for you. Thanks.
hi Logit,
it is working like a charm.
Question is this Precious.wav is windows sound?
It is not added by you?
Jacek
.
That wav file is something I found on the Internet to go along with the image. So Excel takes the wav file you link to by path and makes it a part of the workbook.
No need to carry the wav file and post it into a Temp folder or such.
My personal preference though, were there to be more than a few wav files, is to store them on the users computer in a temp folder. Just for safety sake. I've found
Excel / VBA tends to do what it wants at the most inopportune times.
Kinda like having a wife.
hi Logit,
wow
thank you very much.
How this code is working ?
Call sndPlaySound32(ThisWorkbook.Path & "\My_Precious.wav", 1)How this is working? image with wav? can i add for my image my own wavs?That wav file is something I found on the Internet to go along with the image.
And how to have them in seperate folder?
this is looking wav on disc but there is no file on disc? When it is beeing downloaded?
and where this image is attached to sound?
I am not understanding this but seems awesome!
please help.
p.s i have wife and she is doing what she wants to
Best,
Jacek
.
The image is not involved in playing the wav file.
This macro is in the ThisWorkbook module :
The wav file is played automatically when the workbook is opened. You can also play the wav file by clicking on the button.Please Login or Register to view this content.
And again, the sound will play with or without the image.
As I indicated in my last post, nothing is being downloaded when you open the workbook. The wav file is made part of the workbook via Excel. When you send the workbook
to someone the wav file goes along with the workbook. Again ... nothing is downloaded.
Now, having said that ... if there were a number of wav files to be made a part of the workbook ... my personal preference would be to send those wav files along with the
workbook (if I were sending the workbook to someone else). I would make provisions for the wav files to be placed somewhere on the other person's computer and have the
macro written in such a way for the macro code to reference the wav file/s where they are located on the other person's computer.
thank you Logit,
ok so how can i create wav part as part of Excel?The wav file is made part of the workbook via Excel
And second issue,
So user would have to add these files manually for specific folder yes?my personal preference would be to send those wav files along with the
workbook (if I were sending the workbook to someone else).
Best,
Jacek
Create a workbook with a path to a wav file. Like I did with the example I sent you.ok so how can i create wav part as part of Excel?
Make certain the wav file isn't a part of the Windows operating system. Find something unique
from the internet.
When you send the workbook (you can send the example to me) the sound should play, just as it did in my example.
You could do it that way BUT ... as the programmer, you have the responsibility to include in your coding a meansSo user would have to add these files manually for specific folder yes?
for the project to create the folder with the wav files in it.
Hi Logit,
thank you.
Ok, are you attaching embedded object to workbook and providing path to file?Create a workbook with a path to a wav file
Best,
Jacek
.
No .. I only provided a path in the macro to the wav file on my computer.
What sound do you hear when you open my workbook ?
Last edited by Logit; 04-19-2019 at 03:54 PM.
.
I believe something else is occurring here with the workbook I sent you (posted) as it probably doesn't play the sound on your side. I was presuming it did play the wav file as you were
indicating it did. ????
In any case, your questions prompted me to do some searching for an answer to insure a wav file could be played in a workbook without having to include the wav file itself.
I found this resource which works very well : http://www.vbaexpress.com/forum/show...workbook-opens
If you follow Leith's instructions (very easily done), your workbook will end up with a sheet named "Byte Data" where the wav file (which you have selected from your own computer) is converted and stored.
His example allows for the wav file to play when the workbook is opened. I edited the code to allow for a manual play of the wav file as well.
Please Login or Register to view this content.
Please Login or Register to view this content.
And this macro connected to a button that allows for manual play :
Please Login or Register to view this content.
Both my original workbook and this one were done as an experiment ... for fun. Curiosity more than anything. I still hold to my other recommendation
if the purpose is to have more than one wav file or if the project were something more than a "toy", I would provide for the wav files to be copied to
the users' computer and referenced by file path in the coding.
hi logit,
thank you very much. Awesome help from your side!
Wow this code which is changing wav to bytes and numbers - magic!
I created solution based on sample to have more than 1 wav file in workbook as embedded objects.
When workbook is opening i am creating temporary folder and when workbook is closed - i am dleeting folder with wavs.
And i am using playsound function to run files from specific temporary folder.
Closing the topic.
Thank you once again for help and support,
Jacek
.
I am unable to get a sound to play with your last posted workbook. ????
Hi logit,
i modified file.
Please try buttons on sheet "Play".
On workbook open wav files should be saved into Temp folder (the same path as workbook).
And path ti these files are public so after clicking buttons you should hear audio.
Let me know how it is working for you.
Best,
Jacek
.
Sorry ... no success. I've researched numerous websites for "play embedded wav file" but nothing so far works.
Of course, if I double click on the embedded file icon itself, the wav file plays.
???
Hi Logit,
what error do you have?
If fnBell path is declared on workook open and temp file created? i saw that i have error here :
I tested on second laptop and this is working for me.Please Login or Register to view this content.
Please go to "PlaySoundButtons" module and paste this code:
and you should have as final code:Please Login or Register to view this content.
Best,Please Login or Register to view this content.
Jacek
.
I'm not seeing a TEMP folder created. I've checked my DOWNLOAD folder, the C Drive and several other locations.
This part causes my system issues because I'm running 64 bit O/S and 32 bit Excel :
To get around that error, you can change it to :Please Login or Register to view this content.
I also receive a "Sub or Function Not Defined" on this :Please Login or Register to view this content.
I have been unable to locate a definition of "mciExecute".Please Login or Register to view this content.
What references are you using in the VBE \ Tools \ References dropdown ?
Hi Logit. I will investigate issues after Easter and let you know. In meantime can anybody test on Excel 64 bit if this is working for him? Best wishes Jacek
The image is just like a button, you click it and it runs the macro, how difficult is that to understand?
---
Hans
"IT" Always crosses your path!
May the (vba) code be with you... if it isn't; start debugging!
If you like my answer, Click the * below to say thank-you
.
And if you want to play the sound via a Command Button and not have the windows player appear on screen ?
How difficult is that to understand ?
Hi Guys,
ok so this is working for you Keebellah ? Good.The image is just like a button, you click it and it runs the macro, how difficult is that to understand?
Ok Logit,
first of all , this command is not working for you ?
it should create folder name :Please Login or Register to view this content.
Attachment 621009
What error do you have ? If this is not working, just please create this folder manually.
When i tried to use your code logit:
i have also issue that function is undefined.Please Login or Register to view this content.
Attachment 621010
the code for playing music is from here:
https://books.google.pl/books?id=46t...page&q&f=false
i am very interesting why this is not working for you. We have to fix this together ;-)
Best,
Jacek
Logit,
try to use:
with function:Please Login or Register to view this content.
it is working for you?Please Login or Register to view this content.
Jacek
Are you sure the wav file exists in the TEMP folder?
Keebellah,
for me yes, on workbook open wav files are saved into temp folder.
It is working for you?
If not please help to identify where issue occurs.
Best,
Jacek
This will never work
Please Login or Register to view this content.
This does work
Please Login or Register to view this content.
Ok,
i am attaching the newest code. Please refer to it.
You are referring to old code which is not used.
In module "PlaySoundButtons" we have:
In module mMain i have function declared:Please Login or Register to view this content.
On workbook open i have :Please Login or Register to view this content.
in attachment please find sample workbook and let me know it is working for you.Please Login or Register to view this content.
This sample you posted works perfectly here
Thank you very much,
waiting for Logit and US time
Best,
Jacek
Why're you waiting for them?
Here's your file back with the three buttons, works here
.
jaryszek:
The code is creating the folder in my Downloads folder and naming it: Timer_temp_wav_files
However, it is failing to copy the WAV files into the folder.
The error msg is :
The highlighted line in Workbook_Open macro is :Run-time error '1004'
Method'OLEObjects' of object'_Worksheet' failed
SaveWAVOLEAs WavWb.OLEObjects(BellName), fnBell
Because i would like to have this working for all users.Why're you waiting for them?
this is correct.The code is creating the folder in my Downloads folder and naming it: Timer_temp_wav_files
try solution from here:Run-time error '1004'
Method'OLEObjects' of object'_Worksheet' failed
https://www.excelforum.com/excel-pro...et-failed.html
I changed a code here:
Let me know it is working for you. If not i think we should create new topic for this.Please Login or Register to view this content.
Best,
Jacek
Jacek ...
Sorry ... stilll the same.
Makes the directory but doesn't copy the wav file. Same error message.
Ok can you please create seperate topic?
Working for me and Keebellah and not working for you.
Best,
Jacek
.
That's fine. Thanks.
Best wishes.
Logit,
this is not fine, we should create topic to have this working.
Best,
Jacek
The worksheet failed is probably the old code where SaveEmbedded is stated. there it's looking for a sheet named YesMaster that throws indeed that error
The new folder is indeed a sub-folder of where this excel file is saved, in your case the downloads because you downloaded it there and the was are copied correctly and also removed when you close the file.
No problems here, it also copies three wav files with the names as there are on the sheet in the TEMP folder and these are also removed when closing, so all in all it works.
Just open the file wait and then press one of the buttons. Iadded a debug.print to to sheow where it's getting the file
Ok can you please create seperate topic?Jaryszek - if you want the issue solving, then keep this thread open. There is no need for a new thread, and it certainly is NOT Logit's job to pursue it. If you wish to pursue it here and Logit is happy to answer questions, that's fine, but if not, you will have to let the matter drop. Please do not try to put pressure on other members in this way. Thanks.Logit,
this is not fine, we should create topic to have this working.
Last edited by AliGW; 04-23-2019 at 02:40 AM.
Thank you Kebellah,
working like a charm, thank you for getting involved.
Ali,
nobody is putting pressure on anything
Relax and chill.
Better please tell it is working for you.
Topic is solved, if something is not working for somebody - it is not fine to keep with error but of course - i am not forcing to do anything - it is user choice
Best Wishes,
Jacek
@Jacek: you should read carefully how you formulated your questions and YES it does in a way FORCE and out pressure on others, I agree with Ali, but ... glad it's working
sorry this is my english i am improving all the time but sometimes you can misunderstand me.
Yeeah the most important thing is that this is working. ;-)
Best Wishes,
Jacek
Please don't make comments like this. Thanks.Relax and chill.
Same as Logit this wasn't working for me.
Edited example file from Keebellah in Post#47 to make it work for me too.
@ Logit
Try this example file to see if it's working for you now too.
Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.
bakerman2 thank you!!!
you are awesome man!
Ok i see that you changed "_" for "." - why is that?
JacekPlease Login or Register to view this content.
The problem for me seemed to be that the Objects names weren't recognised with a dot in it.
I replaced the dot in the objects names with an undescore, edited the Const names to the new names and added the Replace to change the undescore back to dot to create the correct filename.
We now have to wait for Logit's response to see if that's a solution for him too and the file works for every user.
Thank you very much,
maybe you have found the issue!
Best wishes,
Jacek
.
bakerman2 ... once again you have come through with a solution !
jaryszek ... bakerman2's editing made the difference. Everything works 100% here now.
Kudos to you and everyone else involved !
Cheers !!!
(ps: Apologies for not responding sooner. I haven't been receiving then notification emails for months now.)
Hi Logit,
glad that we helped
Best,
Jacek
VERY GOOD! But .... When running in 64-bit versions of Office, Declare statements must include the PtrSafe keyword. The PtrSafe keyword asserts that a Declare statement is safe to run in 64-bit development environments.
hi,
without it will not work?
Jacek
That is just to ensure compatibility and make it functional in both versions
Please Login or Register to view this content.
With previous coding Windows Media Player start playing correctly in a different window, but Windows focus does not come back to EXCEL,Please Login or Register to view this content.
even if I force it to stay at top, and the macro pauses: I have to click somewhere on EXCEL window to resume the macro activity.
Any way to bring focus back to EXCEL?
Thanks for your help, I am just beginning to use VBA macros.
(WINDOWS 10 64, Office 2010 64)
Last edited by Labronico; 08-26-2019 at 03:59 AM.
Sorry cannot delete this but my answer is for another post
Buona Notte
BTW this is corrected so that it's 32 and 64 bit compatible
But still there is no media player here so I suggest you start your own post with your question
Hi,
thank you,
you added this "PtrSafe" everywhere into every function? Or there is more changes?
Best,
Jacek
No, just where it's required in the Public Declare Function ...
That's where it belongs
You should Google for this and you'll see what it does and how to use
thank you!
Jacek
Nie ma za co
(Google translate )
[CODE][Sleep 2000 ' control the time of playing/CODE]
[CODE][Shell "taskkill /T /F /IM wmplayer.exe" 'kill the active Windows Media Player instance /CODE]
I reply to my own post.
I solved adding the previous two staments, having forced EXCEL TO STAY ON TOP (as suggested elsewere)
Have you taken a look here?
https://www.myonlinetraininghub.com/...io-video-excel
or here?
https://stackoverflow.com/questions/...n-vba-userform
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks