How to Auto play a MIDI file when document opens 
Author Message
 How to Auto play a MIDI file when document opens

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



Sat, 24 Aug 2002 03:00:00 GMT  
 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



Sat, 24 Aug 2002 03:00:00 GMT  
 How to Auto play a MIDI file when document opens
Thanks Jay - Spot On !!!


Quote:
> 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.



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



Sat, 24 Aug 2002 03:00:00 GMT  
 How to Auto play a MIDI file when document opens
Thinking about this some more...

An embedded or linked OLE object can be either inline (which is handled by
the quoted macro) or floating (which is ignored by that macro). Using the
Format/Object dialog, you could change from one to the other at will. This
version of the macro will check for both possibilities. It also looks only
at the first object in the document... you might have an Excel worksheet
object or any other sort of object in there in addition to the MIDI file,
and you don't really want to activate all of them.

Sub AutoOpen()
Dim oShape As Object

If ActiveDocument.InlineShapes.Count Then
   Set oShape = ActiveDocument.InlineShapes(1)
ElseIf ActiveDocument.Shapes.Count Then
   Set oShape = ActiveDocument.Shapes(1)
Else
   Exit Sub
End If

If (oShape.Type = wdInlineShapeEmbeddedOLEObject) Or _
   (oShape.Type = wdInlineShapeLinkedOLEObject) Or _
   (oShape.Type = msoEmbeddedOLEObject) Or _
   (oShape.Type = msoLinkedOLEObject) Then
   oShape.Activate
End If

End Sub


Quote:
> Thanks Jay - Spot On !!!



[snip]
> > 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

[snip]



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



Sat, 24 Aug 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Playing a MIDI file when doc opens

2. Midi and Wav auto-play

3. How to play MP3 file when document opens

4. Playing WAV files and MIDI files

5. MIDI playing and multiple MIDI's.

6. Playing Midi files from QB 4.5

7. Playing Midi Files In quickbasic 4.5

8. Playing Midi Files on the SB in Quickbasic 4.5

9. Playing MIDI files with QBASIC

10. Routines that play MIDI files...

11. Playing Midi Files

12. Playing MIDI files

 

 
Powered by phpBB® Forum Software