topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 12:05 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Silent msgbox() popup in VBA for Word  (Read 5620 times)

hgondalf

  • Participant
  • Joined in 2010
  • *
  • default avatar
  • Posts: 15
    • View Profile
    • Donate to Member
Silent msgbox() popup in VBA for Word
« on: May 06, 2010, 09:08 AM »
I write lots of VBA applications in the course of my work.  Often I use a msgbox() function, with buttons Yes, No, Cancel, to get a 3-way selection, e.g.,

Select case msgbox("Are you Hot (yes), Cold (no), or Lukewarm (cancel)", VBYesNoCancel)
   case vbyes :  <some code>
   case vbno :  <some code>
   case vbcancel :  <some code>
end select

Trouble is, looping through a long document causes the message box to pop up dozens of times, severely annoying my co-workers and driving me crazy. 

I know I can turn off the notification sound in the Control Panel.  How about writing a little app that could be called from VBA, that would turn on/turn off the sound?  My VBA code would then look like this:

   x = shell ("c:\utils\soundoff.exe off")
  < a little timer delay >
   messgebox ( ) parsing
   x = shell ("c:\utils\soundoff.exe on")

The shell function in VBA returns a value, 0 if no problem, or the program ID otherwise, which is why I have the dummy parameter variable x. 

One can set/reset the sounds in the registry, but I wonder if it is tempting fate to write/rewrite the registry...

How about simply muting the speakers for a moment while the messgebox come up?

BTW I'm running Windows XP HE, but I have Vista and 98 also.

Thanks! 
« Last Edit: May 06, 2010, 09:57 AM by hgondalf »

AbteriX

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 1,149
    • View Profile
    • Donate to Member
Re: Silent msgbox() popup in VBA for Word
« Reply #1 on: May 06, 2010, 03:23 PM »
One can set/reset the sounds in the registry, but I wonder if it is tempting fate to write/rewrite the registry...
What do you think how those other tools would do this?


   x = shell ("c:\utils\soundoff.exe off")
If you want an external tool you can try something like NirSoft NirCMD

http://www.nirsoft.net/utils/nircmd.html

* freeware
* stand alone/portable

Examples:
Mute the system volume    nircmd.exe mutesysvolume 1
Unmute the system volume    nircmd.exe mutesysvolume 0
Switch the system volume between the mute and normal state.    nircmd.exe mutesysvolume 2