Macros to Music

A

Alex

Hi Guys

In my present job i create all the Office templates, all
of which have various simple vba commands that make life
easier for the end users.

Examples Word Functions:
Format tables in the company styles both paragraph and
Borders & Shading
Insert a landscape page in a portrait document and insert
the correct landscape header and footers.

As you might guess some of these macros can take a little
time to run.

We have a few visually impaired users and they have asked
me for a very strange request that I don't know how to do.

What they would like is for a wave file (or mpg file) to
play whilst the macros are running and stop only when the
macro has finished.

Is this possible and if so, how do i do it?

Big thank u in advance

Alex
 
P

Peter Hewett

Hi Alex

It can be done but it's non trivial. You can use the Media Control Interface (MCI)
library "winmm.dll". I haven't tried it so I'm not sure if the calls to MCI are
synchronous or not, I assume that they are asynchronous.

I'd do a Google search on the above and see if you find anything useful.

Sorry that's all I can help you with on this one.

HTH + Cheers - Peter
 
K

Klaus Linke

Hi Alex,

With code stolen from several newsgroup posts:

Private Declare Function sndPlaySound Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) _
As Long

Sub YourMacro()
NotifyStart
' your code
NotifyStop
End Sub

Sub NotifyStart()
Dim sBuf As String
Dim cSize As Long
Dim RetVal As Long
Dim Windir As String
Const SND_SYNC As Long = &H0 'synchronize playback
Const SND_ASYNC As Long = &H1 ' played async
Const SND_NODEFAULT As Long = &H2 ' No default
Const SND_LOOP As Long = &H8 ' 'loop the wave
Const SND_NOSTOP As Long = &H10 'don't stop current sound if one playing
Const SND_NOWAIT As Long = &H2000 'Do not wait if the sound driver is
busy.

Dim n

'Create a variable large enough to store the Windows path.
sBuf = String(255, 0)
cSize = 255

'Get Windows Directory
RetVal = GetWindowsDirectoryA(sBuf, cSize)

'Strip buffer from Windows directory
Windir = Left(sBuf, RetVal)

'Load and Play the sound.
n = sndPlaySound(Windir + "\Media\Notify.wav", SND_ASYNC Or SND_LOOP)

End Sub

Sub NotifyStop()
Const SND_ASYNC As Long = &H1 ' played async
Const SND_NODEFAULT As Long = &H2 ' No default
Dim n

' Stop the loop
n = sndPlaySound(" ", SND_ASYNC And SND_NODEFAULT)
End Sub

Regards,
Klaus
 
A

Alex

Hi Klaus

Thanks for the reply, i've tried the code and it appears
to stop at the following line within the Sub NotifyStart()
section of the code:

RetVal = GetWindowsDirectoryA(sBuf, cSize)

Any ideas?

Big thank you in advance

Alex
 
K

Klaus Linke

Thanks for the reply, i've tried the code and it appears
to stop at the following line within the Sub NotifyStart()
section of the code:

RetVal = GetWindowsDirectoryA(sBuf, cSize)

Any ideas?


Yep, I forgot to paste this:

Private Declare Function GetWindowsDirectoryA Lib "kernel32" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long

(goes at the top of the module, in the declarations, like "Private Declare
Function sndPlaySound ...")

Klaus
 
A

Alex

Klaus
Thank you very much, it works great, my VI users will be
very pleased

Thanks

Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top