Would like a sound, a "Beep", prior to or at the end of a macro

Programming and macros
User avatar
Conklin
Posts: 50
Joined: Fri Mar 26, 2021 3:34 pm
Answers: 0
x 10
x 21

Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by Conklin »

What would be the code that would need to be inserted
to make a "Beep" prior to ending of a macro?
by AlexB » Wed Apr 21, 2021 3:32 pm
Conklin 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?
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.
Go to full post
User avatar
SPerman
Posts: 1894
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 13
x 2066
x 1731
Contact:

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by SPerman »

-
I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
User avatar
DanPihlaja
Posts: 766
Joined: Thu Mar 11, 2021 9:33 am
Answers: 24
Location: Traverse City, MI
x 758
x 910

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by DanPihlaja »

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
User avatar
Frederick_Law
Posts: 1853
Joined: Mon Mar 08, 2021 1:09 pm
Answers: 8
Location: Toronto
x 1558
x 1404

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by Frederick_Law »

Bee Boo Bee Boo Bee Boo

Good to know good old Beep still works.
User avatar
Conklin
Posts: 50
Joined: Fri Mar 26, 2021 3:34 pm
Answers: 0
x 10
x 21

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by Conklin »

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"
User avatar
Roasted By John
Posts: 366
Joined: Mon Mar 08, 2021 3:21 pm
Answers: 1
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

Unread post by Roasted By John »

dpihlaja wrote: Tue Apr 20, 2021 3:03 pm Can you get it to make a Boop as well? Beep Boop would be kind of cool. :)
I'd go for the Bee Bop
www.martinsroastapig.com
Pig Roast Your Way
User avatar
Roasted By John
Posts: 366
Joined: Mon Mar 08, 2021 3:21 pm
Answers: 1
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

Unread post by Roasted By John »

Conklin wrote: Tue Apr 20, 2021 3:10 pm 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"


The message box is just a prompt for you to yell "BeeP"
www.martinsroastapig.com
Pig Roast Your Way
User avatar
HerrTick
Posts: 207
Joined: Fri Mar 19, 2021 10:41 am
Answers: 1
x 32
x 310

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by HerrTick »

I recall it was possible to change the tone of the beep.
http://www.vb-helper.com/howto_net_play_tone.html
image.png
image.png (8.01 KiB) Viewed 4207 times
User avatar
mattpeneguy
Posts: 1382
Joined: Tue Mar 09, 2021 11:14 am
Answers: 4
x 2488
x 1894

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by mattpeneguy »

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
18khz for 5 minutes would be a good starting point. Just make sure to turn the speakers up to 11...
User avatar
jcapriotti
Posts: 1802
Joined: Wed Mar 10, 2021 6:39 pm
Answers: 29
Location: The south
x 1140
x 1947

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by jcapriotti »

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...
image.png
Jason
User avatar
Roasted By John
Posts: 366
Joined: Mon Mar 08, 2021 3:21 pm
Answers: 1
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

Unread post by Roasted By John »

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
User avatar
Conklin
Posts: 50
Joined: Fri Mar 26, 2021 3:34 pm
Answers: 0
x 10
x 21

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by Conklin »

Could it be that in the "Available References:" list for Solidworks it does not have any choice for sounds?
sound ref.jpg
I just thought it would be nice to have the Computer yell at me (Wake me up) when the macro is done.
User avatar
SPerman
Posts: 1894
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 13
x 2066
x 1731
Contact:

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by SPerman »

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
User avatar
Conklin
Posts: 50
Joined: Fri Mar 26, 2021 3:34 pm
Answers: 0
x 10
x 21

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by Conklin »

SPerman
Try just a single beep without the loop.
I did to no avail
User avatar
SPerman
Posts: 1894
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 13
x 2066
x 1731
Contact:

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by SPerman »

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
User avatar
Conklin
Posts: 50
Joined: Fri Mar 26, 2021 3:34 pm
Answers: 0
x 10
x 21

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by Conklin »

Post by SPerman
That works on my computer.
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?
User avatar
AlexB
Posts: 456
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 25
x 246
x 405

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by AlexB »

Conklin 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?
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.
User avatar
SPerman
Posts: 1894
Joined: Wed Mar 17, 2021 4:24 pm
Answers: 13
x 2066
x 1731
Contact:

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by SPerman »

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 may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
User avatar
mattpeneguy
Posts: 1382
Joined: Tue Mar 09, 2021 11:14 am
Answers: 4
x 2488
x 1894

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by mattpeneguy »

SPerman wrote: Wed Apr 21, 2021 3:40 pm 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 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!
User avatar
mattpeneguy
Posts: 1382
Joined: Tue Mar 09, 2021 11:14 am
Answers: 4
x 2488
x 1894

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by mattpeneguy »

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!
Ahhh, but if you go the messy method, you absolutely have to use Flight of the Valkyries!
User avatar
Conklin
Posts: 50
Joined: Fri Mar 26, 2021 3:34 pm
Answers: 0
x 10
x 21

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by Conklin »

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:

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"
He also referenced some on how to play a wave file"

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
Now my next challenge is to get the above to work and then... "Flight of the Valkyries!"
User avatar
Conklin
Posts: 50
Joined: Fri Mar 26, 2021 3:34 pm
Answers: 0
x 10
x 21

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by Conklin »

by 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.
I will try this. Thanks
User avatar
DanPihlaja
Posts: 766
Joined: Thu Mar 11, 2021 9:33 am
Answers: 24
Location: Traverse City, MI
x 758
x 910

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by DanPihlaja »

Conklin wrote: Tue Apr 20, 2021 4:35 pm Could it be that in the "Available References:" list for Solidworks it does not have any choice for sounds?
sound ref.jpg
I just thought it would be nice to have the Computer yell at me (Wake me up) when the macro is done.
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
-Dan Pihlaja
Solidworks 2022 SP4

2 Corinthians 13:14
User avatar
mike miller
Posts: 878
Joined: Fri Mar 12, 2021 3:38 pm
Answers: 7
Location: Michigan
x 1070
x 1232
Contact:

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by mike miller »

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
I don't think Flight of the Valkyries is available from that list. :lol:

Good idea though. :D
He that finds his life will lose it, and he who loses his life for [Christ's] sake will find it. Matt. 10:39
User avatar
Conklin
Posts: 50
Joined: Fri Mar 26, 2021 3:34 pm
Answers: 0
x 10
x 21

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by Conklin »

by 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.
Good idea. When I get time I'll try that too. Thanks
User avatar
HerrTick
Posts: 207
Joined: Fri Mar 19, 2021 10:41 am
Answers: 1
x 32
x 310

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by HerrTick »

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!!! =) tu
image.png
image.png (44.32 KiB) Viewed 4090 times
Attachments
image.png
image.png (44.32 KiB) Viewed 4090 times
User avatar
Conklin
Posts: 50
Joined: Fri Mar 26, 2021 3:34 pm
Answers: 0
x 10
x 21

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by Conklin »

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.
I did mark you as the correct answer... based on your "Edit: I just tested it and it works great."
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...
User avatar
Conklin
Posts: 50
Joined: Fri Mar 26, 2021 3:34 pm
Answers: 0
x 10
x 21

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by Conklin »

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.

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
Now I just figured out / or better said happen to place the end sub in the right location
And now it works Thanks All.
User avatar
Conklin
Posts: 50
Joined: Fri Mar 26, 2021 3:34 pm
Answers: 0
x 10
x 21

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by Conklin »

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? o[
User avatar
mattpeneguy
Posts: 1382
Joined: Tue Mar 09, 2021 11:14 am
Answers: 4
x 2488
x 1894

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by mattpeneguy »

Conklin wrote: Fri Apr 23, 2021 3:39 pm 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? o[
Check your Private Messages.
User avatar
HerrTick
Posts: 207
Joined: Fri Mar 19, 2021 10:41 am
Answers: 1
x 32
x 310

Re: Would like a sound, a "Beep", prior to or at the end of a macro

Unread post by HerrTick »

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
Post Reply