
How to Auto play a MIDI file when document opens
This works for me:
Sub AutoOpen()
Dim cmd As String
On Error GoTo bye
cmd = "C:\Program Files\Windows Media Player\mplayer2.exe /Play "
cmd = cmd + "D:\test.mid" ' modify to your file's path
Shell cmd
bye:
End Sub
If you use the Insert/Object menu to link or embed the MIDI file in the
document (and it's the only object in the file), then this macro will do the
job:
Sub AutoOpen()
Dim oShape As InlineShape
If ActiveDocument.InlineShapes.Count Then
For Each oShape In ActiveDocument.InlineShapes
If (oShape.Type = wdInlineShapeEmbeddedOLEObject) Or _
(oShape.Type = wdInlineShapeLinkedOLEObject) Then
oShape.Activate
End If
Next oShape
End If
End Sub
There are some things to know about this:
- The subroutine name AutoOpen is a special one that Word looks for every
time it opens a document. If it's present in the document being opened, or
in normal.dot or in one of the templates loaded from Word's Startup folder,
then it executes.
- You should save this macro in the document and *not* in a template unless
you want the same MIDI file to play for every document. The downside is that
this will kick off Word's macro virus warning.
- If you distribute this for other people to use, you have to make sure that
they have mplayer2.exe and the MIDI file in the places where the macro
expects them to be.
Quote:
> Hi All,
> Can someone please email me and let me know how best to create the effect
> I'm looking for, which is basically just to automatically kick of a MIDI
> file when a user opens a Word document. I'm not a coder and don't
> understand VBA but I'm sur this can be sone pretty simply.
> Regs.
> Matt