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
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.
Mystery <mys...@barrysworld.co.uk> wrote in message
news:8a2p9p$32b$1...@news7.svr.pol.co.uk...
Jay Freedman <jfr...@i-bob.com> wrote in message
news:uR4T$CEi$GA....@cppssbbsa02.microsoft.com...
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
Mystery <mys...@barrysworld.co.uk> wrote in message
news:8a33us$8ib$1...@news7.svr.pol.co.uk...
> Thanks Jay - Spot On !!!
>
>
> Jay Freedman <jfr...@i-bob.com> wrote in message
> news:uR4T$CEi$GA....@cppssbbsa02.microsoft.com...
[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]