How to Mute/Enable Windows Sounds whilst running VBA code

Most of the time, my PC runs silently.  I am easily irritated by sounds of
windows opening, etc. etc.  But exceptionally, I would like to be advised of
an unusual event by playing a Wav file through code.  Is there a pair of
lines that I can add to enable before, and mute after the required sound has
played?  Here is an example:

Private Declare Function PlaySound Lib "winmm.dll" _
  Alias "PlaySoundA" (ByVal lpszName As String, _
  ByVal hModule As Long, ByVal dwFlags As Long) As Long

Public Sub PrinterCheck()

Dim int1as integer
Dim strWavFile As String

    int1 = MsgBox("Ready to Print?", vbYesNoCancel)
        boolNP = True
    If int1 = 6 Then
        strWavFile = ThisWorkbook.Path & "\sound1.wav"
        boolNP = False
    ElseIf int1 = 7 Then
        strWavFile = ThisWorkbook.Path & "\sound2.wav"
    End If
    Call PlaySound(strWavFile, 0&, SND_ASYNC Or SND_FILENAME)

End Sub


0
Hotbird
8/15/2004 8:23:28 AM
excel.misc 78881 articles. 5 followers. Follow

2 Replies
850 Views

Similar Articles

[PageSpeed] 39

Give this a try

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


Sub ChangeVolumeMute()
Dim oShell As Object

    On Error Resume Next
    Set oShell = GetObject(, "WScript.Shell")
    If oShell Is Nothing Then
        Set oShell = CreateObject("WScript.Shell")
    oShell.Activate
    End If
    oShell.Run "Sndvol32"
    Sleep 1500
    oShell.SendKeys "{TAB 2} "
End Sub


-- 

HTH

Bob Phillips
    ... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Hotbird" <hotbird62.@tesco.net> wrote in message
news:44FTc.279$dP1.55@newsfe6-gui.ntli.net...
> Most of the time, my PC runs silently.  I am easily irritated by sounds of
> windows opening, etc. etc.  But exceptionally, I would like to be advised
of
> an unusual event by playing a Wav file through code.  Is there a pair of
> lines that I can add to enable before, and mute after the required sound
has
> played?  Here is an example:
>
> Private Declare Function PlaySound Lib "winmm.dll" _
>   Alias "PlaySoundA" (ByVal lpszName As String, _
>   ByVal hModule As Long, ByVal dwFlags As Long) As Long
>
> Public Sub PrinterCheck()
>
> Dim int1as integer
> Dim strWavFile As String
>
>     int1 = MsgBox("Ready to Print?", vbYesNoCancel)
>         boolNP = True
>     If int1 = 6 Then
>         strWavFile = ThisWorkbook.Path & "\sound1.wav"
>         boolNP = False
>     ElseIf int1 = 7 Then
>         strWavFile = ThisWorkbook.Path & "\sound2.wav"
>     End If
>     Call PlaySound(strWavFile, 0&, SND_ASYNC Or SND_FILENAME)
>
> End Sub
>
>


0
bob.phillips1 (6510)
8/15/2004 10:51:45 AM
Hi,

Try the following code:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub TEST()

    Dim WSS As Object

    On Error Resume Next
    Set WSS = GetObject(, "WScript.Shell")
    If WSS Is Nothing Then Set WSS = CreateObject("WScript.Shell")
    On Error GoTo 0

    WSS.Run "Sndvol32"
    Sleep 1000
    WSS.SendKeys "{TAB 2} %PX"

    Set WSS = Nothing

End Sub
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


--
Regards,
Soo Cheon Jheong
_  _
^��^
 -- 




0
exceler (34)
8/16/2004 3:20:26 AM
Reply:

Similar Artilces:

NVTV Tuner on Windows 7?
According to at least one poster, the NVTV dual tuner card works with Windows 7. Has anyone here been able to get that to work? I'm curious because I absolutely love the capabilities of that card and would like to bring it into one of my current builds. However, I had understood that this card was only supported on Windows XP MCE 2005. Source: http://www.dslreports.com/forum/r23258528-BLOG-Why-Windows-7-may-still-fail -Pete ...

Set subform record enable/no enabled
Hi Guys, I have a subform bound to a query. As part of that query is a checkbox, [chkSelect] to allow users to select or de-select items on the subform, what I am looking to do is, if the checkbox is selected I want the record to be set as enabled = no if the record is not selected I want enabled = yes The subform is layout out as a form not datasheet. Thanks On Thu, 4 Feb 2010 14:02:32 -0000, "EddWood" <Edd_nospam_@Wood\hotmail.co.uk> wrote: Try this: in the Form_Current event write: Me.AllowEdits = Not Me!chkSelect -Tom. Microsoft Access MVP ...

Control disable/enable question
I'm trying to enable/disable a command button, based on a check box(table field), on a continuous form. This form is a one-liner with only 6 items. The weird thing is, if say 8 records(line items) are shown, changing the check box on any one of the line items causes all other line's buttons to respond, not just that particular line I'm editing. The code I've tried is: Private Sub Testbutton_AfterUpdate() If Me.chkBox = True Then Me.cmdButton.Enabled = True Else: Me.cmdButton.Enabled = False End Sub I've used this in a single forms successfully, but not continu...

Syntax to run a macro for several folders
I have the following macro to mark all messages as read. I want to call it with a list so that it will run for several folders. What syntax would I use? Thanks. Sub ChangeToRead() Dim objInbox As Outlook.MAPIFolder Dim objOutlook As Object, objnSpace As Object, objMessage As Object Dim objSubfolder As Outlook.MAPIFolder Set objOutlook = CreateObject("Outlook.Application") Set objnSpace = objOutlook.GetNamespace("MAPI") Set objInbox = objnSpace.GetDefaultFolder(olFolderInbox) 'Set objSubfolder = objInbox.Folders.Item("Test") Set objSubfold...

VBA code error with Protection turned on
I am using Excel 97-SR2. The code below is used to set a cell to a particular colour, dependent upon the value entered. The cell (in range A3:IV3) is used as an indicator to show the status of the data being entered as follows R - Red A - Amber G - Green P - Pending Completion C - Complete H - On hold D - Draft The 2 subroutines allow the data to be either typed in or selected from a validation list (a Named list on a separate "Lookups" worksheet in the same spreadsheet), the colours are set by macro to get around the Conditional formatting limit of 3/4 colours. All was working w...

Enable the autocomplete of text control (IE control) in CDHtmlDial
I am wondering how can I enable the autocomplete function with the (web) text control in CDHtmlDialg, similar to that when I browse it (HTML file) in the IE. ...

how to read Word file on a Windows 2000 PC
Version: 2004 Operating System: Mac OS X 10.4 (Tiger) Processor: Intel I created a Word file on my Macbook and when I tried to open the file on my work PC which is a Windows 2000 PC with Word for Windows 2000, I cant open the file. Is there a way I can save this file on my Macbook to allow it to be opened on the Windows computer please? <br><br>Thank you <br><br>Veedeekay You would be much more likely to get a specific response if you'd describe how the file is "getting to" the PC, exactly what happens when you try to open it, & a general in...

Split window
Is there a way when you split your window to scroll vertically only on one side of the split and not the other? Thanks, Josh -- jspizman ------------------------------------------------------------------------ jspizman's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=30694 View this thread: http://www.excelforum.com/showthread.php?threadid=504530 No, but try Window>New Window then Window>Arrange>Vertical. You now have two windows that will scroll independently. Gord Dibben MS Excel MVP On Tue, 24 Jan 2006 10:51:20 -0600, jspizman <jspizman.2...

my latest C++ excel OLE automation code
// fm2n_old.cpp // The OLE Automation interface to Excel is mostly written using: // "How to automate Excel from C++ without using MFC or #import" // http://support.microsoft.com/kb/216686 #include <stdio.h> #include <string.h> #include <stdlib.h> #include <windows.h> #include <comdef.h> #include "ole2.h" #include <ctype.h> #include <shellapi.h> #include "asstring.h" #include "fm2n_old.h" // main pointer for Excel IDispatch * pExcelApplication = NULL; // Workbooks collection IDispatch * pExcelWor...

sound delayed
I have added music to a ppt to play across slides and loop until stopped. When I run the presentation it takes until the 3rd or 4th slide to start. It is a midi file about 28K. What am I am I doing wrong? I want the music to start when the presentation starts. What version of PPT? Have you viewed the animation pane and confirmed the audio file is the first item in the animation list? -- Troy @ TLC MS PowerPoint MVP Check out www.ThePowerPointBlog.com "vlh" <vlh@discussions.microsoft.com> wrote in message news:585771A5-C995-4EB4-A3F9-A997B5BB6477@micros...

Windows Mail
We've just moved and are getting cable internet service from same provider (Cogeco), but with new password. I can't get on Windows Mail, but can go to my Internet provider for email service. This message keeps popping up: Account: 'pop.cogeco.ca', Server: 'pop.cogeco.ca', Protocol: POP3, Server Response: '-ERR unknown command', Port: 110, Secure(SSL): No, Server Error: 0x800CCC90, Error Number: 0x800CCC18 Any help most appreciated. Windows Mail is more convenient,(if I could get it!!) Thanks, BillF "BillF" <BillF@discussions.m...

Enabling Macros #4
Is there anyway possible that for every user that opens a workbook with macros the Enable Macro question box will not pop up and the macros will always be enabled? The workbook that I am creating will be used by many people with different versions of Excel and limited knowledge of Excel so the macros may be disabled causing errors. Thanks for the help! Hi the only way would be that your users set the security level to 'Low'. BUT I wouldn't recommend this. this is a security feature. So there should be no way tro disable it programmatically :-) -- Regards Frank Kabel Frank...

cant run best practices analyzer tool
Hey guys hoping for some quick help on this, I'm trying to run the exchange best practices tool on my windows 2003/exchange 2003 tool but I cant get it to work. It continuously says that it cant connect to the exchange server even though my server is running fine and email works. When I view the report it always says that the registry cannot be accessed on the exchange server, I did everything that list specified like made sure that the remote registry service was running and that my account has permissions, the account I run it under is an administrator account. Still keeps saying ...

Problems with Window in Dialog Owner Draw? #4
I Skin the CDialog based windows,in the window,the Minbox and MaxBox and CloseBox are exist,the title bar are Owner drawed of cause and the three "button",They show well,but the button in the task bar that stand for the Dialog ,does not work well, when the dialog is active,you click the button in task bar the dialog can not hide(Or as we say the dialog in min state.). thanks, Tylor ...

Photo Story 3 lower sound on narrated slides
I have Photo Story 3. I have music that covers ten slides. For the 4th slide, I want to lower the music volume and enter a narration. I click on the 4th slide, then use the slide to lower the volume. HOWEVER, when I Review this change, the volume changes on all ten of the slides. How do i lower music volume on only selectedd slides, while maintaining a higher volume on the other slides? Thank you. Steve Shouldn't you go to that companies website and ask them? This is a dicussion for Windows XP not Photo Story 3 or even the movie Toy Story. "Steve" <...

How do I draw shapes on a user form? (VBA Excel 2007)
I'm trying to draw shapes on a user form (ie arrows, circles, ovals, etc). Can this be done? hi, ! > I'm trying to draw shapes on a user form (ie arrows, circles, ovals, etc). > Can this be done? try with this: Drawing on userform (Excel 2000 and above) http://www.andypope.info/vba/userformdraw.htm hth, hector. ...

Windows CE power off message
Hi, Is there a way to detect that a windows CE device is being turned off? The device is running Windows CE .NET version 4.2. We have a data input card attached that doesn't alway recover if we're in the middle of taking a measurement when the power goes off. I'd like to pause measurements before the unit shuts down. Regards, Ask in NG microsoft.public.windowsce.embedded.vc Regards, Guido "mfr" <mfr@community.nospam> schrieb im Newsbeitrag news:41A6E3B8-2A04-4EEA-94EF-09958281B559@microsoft.com... > Hi, > > Is there a way to detect that a window...

Running macros when Excel starts up
Hi How do I get macros or some code to run automatically when I start up an excel worksheet? Thanks I think you mean workbook, not sheet, correct? Open your workbook. Hit Alt+F11 or Tools-->Macro-->Visual Basic Editor. Double-click ThisWorkbook on the left below your Project's name. On the right, hit the first dropdown and choose Workbook. You can choose other events on the right-hand dropdown, but the Workbook_Open appears already, so just place your code between the Private... and End Sub. ******************* ~Anne Troy www.OfficeArticles.com "Solly" <Solly@disc...

enabling intelligent message filtering
I'm trying to enable IMF on my Exchange server (I have SP2 installed). I've configured all the IMF parameters as explained in this URL: http://www.microsoft.com/technet/prodtechnol/exchange/guides/IMFDeploy/ca384ce8-32c4-4d38-9227-eb27ce9b08a3.mspx?mfr=true However at the bottom of that URL, it says to enable IMF, I need to 1. In Exchange System Manager, expand Servers, expand <Server name>, expand Protocols, expand SMTP, right-click Intelligent Message Filtering, and then click Properties. However, I do not have an entry under SMTP for IMF. I'm wondering w...

Do you tick "Enable file and folder compression" when formatting a data volume?
Dear all, I just added 2 x 600GB HDDs into a Dell PE2900 to form a RAID1 data volume. I am wondering if it is okay to tick the option "Enable file and folder compression" when formatting this new volume so that I can save more data on it. Are there any side effects to do this? Thanks Jack On Wed, 23 Dec 2009 12:28:32 -0800 (PST), Jack <dontaskwhoiam2001@gmail.com> wrote: >Dear all, > >I just added 2 x 600GB HDDs into a Dell PE2900 to form a RAID1 data >volume. > >I am wondering if it is okay to tick the option "Enable file and >...

Outlook XP
When I reply or start a new message, it doesn't appear on my screen, even though it shows in the task bar. F11 doesn't help - there doesn't seem to be any way to show the window. What SP level is Office/Outlook? --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (insert latest virus name here) virus, all mail sent to my personal account will be deleted without reading. After searching google.groups.com and finding no answer, Cynthia asked: | When I reply or start a new message, it doesn't appear on | my screen, ev...

Edit a web query in Excel 2002 that runs a dialogue box for the user to input the name of the city.
I am trying to set up This name is then used by the web query to complete the UR eg http://www.onlineweather.com/v4/world/owac/EU/climate/Athens.html or http://www.onlineweather.com/v4/world/owac/EU/climate/Cork.htm In early editions of Excel this involved inserint the live /[“city” “which city?”].html eg http://www.onlineweather.com/v4/world/owac/EU/climate/[“city” “which city?”].htm Has anyone worked out how to do this in Excel 2002 ...

Native Mode in Windows 2003
I am doing a test install of CRM 1.2 on a Windows 2003 environment. During the install it tells me that I must be in Native Mode. When in Administration Tools -> Active Directory Domains and Trusts and I right mouse clice and select Raise Domain Functional Level I am shown as being in Windows 2000 mixed. My choices are Windows 2000 native or Windows 2003. Which should I select? I am not an AD or Windows 2003 guru. Alan Hi Alan, This should work with both options, it all depends on your domain architecture. Do you have any other NT4 DC ? if not you can move easily to Windows 2000...

ClistView disappears when windows go back
Hi all, I have a problem with ClistView control. I have a CDialog form and a tab control on it and there is a listview on one of the tabs. When we switch to a different window and come back, the listview control disappears and not visible until i click on it or list the elements of it. Hovewer, the other controls on the tab are visible and works properly. How can i fix this? Thanks in advance.. Dogal Acar This comes up often. I think there is a flaw in the notification mechanism. I also think you can fix it by setting up a OnSetFocus() funtion and invalidating the list control so it wil...

Auto Enable Macro
I download SpellIndian function by Yogi Anand from anandent.com, for my invoice template, I insert code in to VBE standard module. Now I want to automate the code i.e. when I open worksheet it is auto enable and when I close worksheet it is automtic disable. I have one worksheet for my invoice template. I don't understand how can I automate my macro. I am not a programmer, so please someone explaine me in details. My code is below. Function SpellIndian(ByVal MyNumber) '**** Yogi Anand -- ANAND Enterprises -- Rochester Hills MI 48309 -- 248-375-5710 www.anand...