Would like a sound, a "Beep", prior to or at the end of a macro
Would like a sound, a "Beep", prior to or at the end of a macro
What would be the code that would need to be inserted
to make a "Beep" prior to ending of a macro?
to make a "Beep" prior to ending of a macro?
I'm not sure if it even works, but this came up with a quick search about playing sound files with VBAConklin wrote: ↑Wed Apr 21, 2021 3:20 pm I did it again (with out loop) and a single beep command, and yes it makes a sound BUT I think it is just a sound that is a standard sound when a message box is displayed and it, the macro, wants a user input.
Is there a way to have a macro run, pull, or retrieve a sound, say a "wav" file, off the hard drive and play it from within the SW macro?
https://en.wikibooks.org/wiki/Visual_Ba ... e_from_VBA
Edit: I just tested it and it works great. Any WAV file plays with the message box.
Re: Would like a sound, a "Beep", prior to or at the end of a macro
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
- DanPihlaja
- Posts: 849
- Joined: Thu Mar 11, 2021 9:33 am
- Location: Traverse City, MI
- x 812
- x 980
Re: Would like a sound, a "Beep", prior to or at the end of a macro
Can you get it to make a Boop as well? Beep Boop would be kind of cool.
-Dan Pihlaja
Solidworks 2022 SP4
2 Corinthians 13:14
Solidworks 2022 SP4
2 Corinthians 13:14
- Frederick_Law
- Posts: 1948
- Joined: Mon Mar 08, 2021 1:09 pm
- Location: Toronto
- x 1638
- x 1471
Re: Would like a sound, a "Beep", prior to or at the end of a macro
Bee Boo Bee Boo Bee Boo
Good to know good old Beep still works.
Good to know good old Beep still works.
Re: Would like a sound, a "Beep", prior to or at the end of a macro
I added this bit Got the message boxes but no Beeps between
MsgBox "beep Start"
Dim x
For x = 1 To 10 ' Loop 10 times.
Beep ' Sound a tone.
Next x
MsgBox "beep done"
MsgBox "beep Start"
Dim x
For x = 1 To 10 ' Loop 10 times.
Beep ' Sound a tone.
Next x
MsgBox "beep done"
- Roasted By John
- Posts: 366
- Joined: Mon Mar 08, 2021 3:21 pm
- Location: Lebanon PA USA
- x 268
- x 583
- Contact:
Re: Would like a sound, a "Beep", prior to or at the end of a macro
I'd go for the Bee Bop
www.martinsroastapig.com
Pig Roast Your Way
Pig Roast Your Way
- Roasted By John
- Posts: 366
- Joined: Mon Mar 08, 2021 3:21 pm
- Location: Lebanon PA USA
- x 268
- x 583
- Contact:
Re: Would like a sound, a "Beep", prior to or at the end of a macro
The message box is just a prompt for you to yell "BeeP"
www.martinsroastapig.com
Pig Roast Your Way
Pig Roast Your Way
Re: Would like a sound, a "Beep", prior to or at the end of a macro
I recall it was possible to change the tone of the beep.
http://www.vb-helper.com/howto_net_play_tone.html
http://www.vb-helper.com/howto_net_play_tone.html
- mattpeneguy
- Posts: 1386
- Joined: Tue Mar 09, 2021 11:14 am
- x 2489
- x 1899
Re: Would like a sound, a "Beep", prior to or at the end of a macro
18khz for 5 minutes would be a good starting point. Just make sure to turn the speakers up to 11...HerrTick wrote: ↑Tue Apr 20, 2021 3:19 pm I recall it was possible to change the tone of the beep.
http://www.vb-helper.com/howto_net_play_tone.html
image.png
- jcapriotti
- Posts: 1869
- Joined: Wed Mar 10, 2021 6:39 pm
- Location: The south
- x 1214
- x 1999
Re: Would like a sound, a "Beep", prior to or at the end of a macro
mattpeneguy wrote: ↑Tue Apr 20, 2021 3:46 pm 18khz for 5 minutes would be a good starting point. Just make sure to turn the speakers up to 11...
Jason
- Roasted By John
- Posts: 366
- Joined: Mon Mar 08, 2021 3:21 pm
- Location: Lebanon PA USA
- x 268
- x 583
- Contact:
Re: Would like a sound, a "Beep", prior to or at the end of a macro
Actually, just waiting for one of my co-workers to come back to his office, just sent him a chat note that had Cat sounds, but I turned his speakers all the way up...... MEOW GRRR
www.martinsroastapig.com
Pig Roast Your Way
Pig Roast Your Way
Re: Would like a sound, a "Beep", prior to or at the end of a macro
Could it be that in the "Available References:" list for Solidworks it does not have any choice for sounds?
I just thought it would be nice to have the Computer yell at me (Wake me up) when the macro is done.Re: Would like a sound, a "Beep", prior to or at the end of a macro
Try just a single beep without the loop.
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
Re: Would like a sound, a "Beep", prior to or at the end of a macro
I did to no availSPerman
Try just a single beep without the loop.
Re: Would like a sound, a "Beep", prior to or at the end of a macro
That works on my computer.
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
Re: Would like a sound, a "Beep", prior to or at the end of a macro
I did it again (with out loop) and a single beep command, and yes it makes a sound BUT I think it is just a sound that is a standard sound when a message box is displayed and it, the macro, wants a user input.Post by SPerman
That works on my computer.
Is there a way to have a macro run, pull, or retrieve a sound, say a "wav" file, off the hard drive and play it from within the SW macro?
Re: Would like a sound, a "Beep", prior to or at the end of a macro
I'm not sure if it even works, but this came up with a quick search about playing sound files with VBAConklin wrote: ↑Wed Apr 21, 2021 3:20 pm I did it again (with out loop) and a single beep command, and yes it makes a sound BUT I think it is just a sound that is a standard sound when a message box is displayed and it, the macro, wants a user input.
Is there a way to have a macro run, pull, or retrieve a sound, say a "wav" file, off the hard drive and play it from within the SW macro?
https://en.wikibooks.org/wiki/Visual_Ba ... e_from_VBA
Edit: I just tested it and it works great. Any WAV file plays with the message box.
Re: Would like a sound, a "Beep", prior to or at the end of a macro
I found several references for playing a wave file, but it was all pre windows 10, so I wasn't sure if any of them would work.
I guess it is more of a ding than a beep.
I guess it is more of a ding than a beep.
-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
- mattpeneguy
- Posts: 1386
- Joined: Tue Mar 09, 2021 11:14 am
- x 2489
- x 1899
Re: Would like a sound, a "Beep", prior to or at the end of a macro
I think this is doable, but if the VBA isn't working inside the API to play the sound, it's going to get convoluted. I'm pretty darn sure you can use a string in VBA to call an application and send it a file to play and it'll work...But, man is that messy!
- mattpeneguy
- Posts: 1386
- Joined: Tue Mar 09, 2021 11:14 am
- x 2489
- x 1899
Re: Would like a sound, a "Beep", prior to or at the end of a macro
Ahhh, but if you go the messy method, you absolutely have to use Flight of the Valkyries!mattpeneguy wrote: ↑Wed Apr 21, 2021 3:56 pm I think this is doable, but if the VBA isn't working inside the API to play the sound, it's going to get convoluted. I'm pretty darn sure you can use a string in VBA to call an application and send it a file to play and it'll work...But, man is that messy!
Re: Would like a sound, a "Beep", prior to or at the end of a macro
OK so I got the beep to work
Via A " Duck Duck Go" search that turned up a Thread on the "Old Fourm":
What do you think about a Confirmation BEEP?
Asked by Dan Golthing | 05/30/19 |
In it a reply by Thomas Allsup
Where he references a presentation he did I think at SW World:
2008 one minute presentation: "One Minute Tip"
So I came up with this code:
He also referenced some on how to play a wave file"
Now my next challenge is to get the above to work and then... "Flight of the Valkyries!"
Via A " Duck Duck Go" search that turned up a Thread on the "Old Fourm":
What do you think about a Confirmation BEEP?
Asked by Dan Golthing | 05/30/19 |
In it a reply by Thomas Allsup
Where he references a presentation he did I think at SW World:
2008 one minute presentation: "One Minute Tip"
So I came up with this code:
Code: Select all
MsgBox "beep Start"
Start = 0
Pause = 10 ' Pause
Start = Timer ' Set start time.
Do While Timer < Start + Pause
Beep
Loop
MsgBox "beep done"
Code: Select all
Declare Function sndPlaySound32 Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Sub PlaySound()
Call sndPlaySound32("c:\solidworks.wav", 0)
End Sub
Call PlaySound
Re: Would like a sound, a "Beep", prior to or at the end of a macro
I will try this. Thanksby AlexB
https://en.wikibooks.org/wiki/Visual_Ba ... e_from_VBA
Edit: I just tested it and it works great. Any WAV file plays with the message box.
- DanPihlaja
- Posts: 849
- Joined: Thu Mar 11, 2021 9:33 am
- Location: Traverse City, MI
- x 812
- x 980
Re: Would like a sound, a "Beep", prior to or at the end of a macro
Just configure your sounds inside Solidworks and have the last line of your macro do something from the list.
Might make it cumbersome, though. But if the last line of your macro is a rebuild, then configure the rebuild complete sound to whatever you want.
-Dan Pihlaja
Solidworks 2022 SP4
2 Corinthians 13:14
Solidworks 2022 SP4
2 Corinthians 13:14
- mike miller
- Posts: 878
- Joined: Fri Mar 12, 2021 3:38 pm
- Location: Michigan
- x 1070
- x 1231
- Contact:
Re: Would like a sound, a "Beep", prior to or at the end of a macro
I don't think Flight of the Valkyries is available from that list.dpihlaja wrote: ↑Thu Apr 22, 2021 8:02 am Just configure your sounds inside Solidworks and have the last line of your macro do something from the list.
Might make it cumbersome, though. But if the last line of your macro is a rebuild, then configure the rebuild complete sound to whatever you want.
image.png
Good idea though.
He that finds his life will lose it, and he who loses his life for [Christ's] sake will find it. Matt. 10:39
Re: Would like a sound, a "Beep", prior to or at the end of a macro
Good idea. When I get time I'll try that too. Thanksby dpihlaja » Thu Apr 22, 2021 8:02 am
Just configure your sounds inside Solidworks and have the last line of your macro do something from the list.
Might make it cumbersome, though. But if the last line of your macro is a rebuild, then configure the rebuild complete sound to whatever you want.
Re: Would like a sound, a "Beep", prior to or at the end of a macro
There's a trick to going up the chromatic scale.
Each half-step's frequency is 2^(1/12) times greater than the previous. You can extend this ad infinitum.
Take A=440Hz
B is two half-steps higher --> B = A * 2^(2/12)
C is 3 half-steps greater --> C = A * 2^(3/12)
Note an octave's frequency is double the root. A2 = A1 * 2^(12/12) = A1 * 2^1 = A1*2
Logarithms!!!
Each half-step's frequency is 2^(1/12) times greater than the previous. You can extend this ad infinitum.
Take A=440Hz
B is two half-steps higher --> B = A * 2^(2/12)
C is 3 half-steps greater --> C = A * 2^(3/12)
Note an octave's frequency is double the root. A2 = A1 * 2^(12/12) = A1 * 2^1 = A1*2
Logarithms!!!
- Attachments
-
- image.png (44.32 KiB) Viewed 5022 times
Re: Would like a sound, a "Beep", prior to or at the end of a macro
I did mark you as the correct answer... based on your "Edit: I just tested it and it works great."by AlexB
I'm not sure if it even works, but this came up with a quick search about playing sound files with VBA
https://en.wikibooks.org/wiki/Visual_Ba ... e_from_VBA
Edit: I just tested it and it works great. Any WAV file plays with the message box.
BUT
I tried to make it work as well but after several hours I give up.
Alex, if you could post the code you used to test.... that would be greatly appreciated.
I am doing something wrong. I am just knowledgeable enough to be dangerous with API.
but I can follow an example... and paste it in to a macro I am using... I think...
Re: Would like a sound, a "Beep", prior to or at the end of a macro
OK so I dropped the below code just as it was on the web page
into a new SW macro and and it works great
I guess I was trying to think too much for I was trying to put it into/at the end of an existing macro
and could not get it to work.
Now I just figured out / or better said happen to place the end sub in the right location
And now it works Thanks All.
into a new SW macro and and it works great
I guess I was trying to think too much for I was trying to put it into/at the end of an existing macro
and could not get it to work.
Code: Select all
Option Explicit
'Declaration for Win10 and Office 64 bit
Public Declare PtrSafe Function sndPlaySound Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
Sub TestPlayWavFileAPI()
'run this to play a sound wave (.wav) file
Dim sPath As String
'path to wave file - replace with your own
sPath = "C:\Windows\Media\Ring08.wav"
'test the no-wait feature
PlayWavFileAPI sPath, False
MsgBox "This message box appears during the sound"
'test the wait feature
PlayWavFileAPI sPath, True
MsgBox "This message appears only after the sound stops"
End Sub
Function PlayWavFileAPI(sPath As String, Wait As Boolean) As Boolean
'API declaration of sndPlaySound is modified for 64 bit windows
'and tests well in Excel 2019 vba version 7.1.
'For earlier versions it might be necessary to remove the word PtrSafe
'from the declaration, or to consider another format.
'make sure file exists
If Dir(sPath) = "" Then
Exit Function
End If
If Wait Then
'hold up follow-on code until sound complete
sndPlaySound sPath, 0
Else
'continue with code run while sound is playing
sndPlaySound sPath, 1
End If
End Function
And now it works Thanks All.
Re: Would like a sound, a "Beep", prior to or at the end of a macro
NOW
Where do I find, I think it is, "The ride of the Valkyries"
In a "WAV" format !!!!!!
Can an "MP3" be converted?
Or
Do I now have to figure out how to get a "MP3" to work?
Where do I find, I think it is, "The ride of the Valkyries"
In a "WAV" format !!!!!!
Can an "MP3" be converted?
Or
Do I now have to figure out how to get a "MP3" to work?
- mattpeneguy
- Posts: 1386
- Joined: Tue Mar 09, 2021 11:14 am
- x 2489
- x 1899
Re: Would like a sound, a "Beep", prior to or at the end of a macro
If you want to use sound files, you would do well to learn about resource modules in VB. A resource module lets you store files for access by the program, without having to have the file reside at a specific address on your drive.
disclaimer: My API kung fu is old. This is VB6 or VBA circa 2010. It appears VB.NET has as well.
https://www.thoughtco.com/vbnet-resource-files-3424443
disclaimer: My API kung fu is old. This is VB6 or VBA circa 2010. It appears VB.NET has as well.
https://www.thoughtco.com/vbnet-resource-files-3424443