Change Control Property from VBA Code

Joe Was

MrExcel MVP
Joined
Feb 19, 2002
Messages
7,539
I have a working MediaPlayer on a sheet, the "PlayCount" and "FileName" for that control is set within the Property Dialog Box. Now I want to set those properties from Macro code for flexibility. Any ideas, code samples, it could be from another control they should work the same? JSW
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
I just figured out the MediaPlayer control last night. The only thing I was able to figure out was how to set the file you wish to play.

MediaPlayer1.Open ("C:winntmediatada.wav")

I hope this helps.
 
Upvote 0
Have a look @ the underlying Event code for the control ie. right click select view code.
This is the easiest place to get the correct syntax eg

<pre/>
Private Sub MediaPlayer1_GotFocus()
MediaPlayer1.Open ("C:WINDOWSMEDIABach's Brandenburg Concerto No. 3.rmi")
'MediaPlayer1.Filename = "C:WINDOWSMEDIACanyon.mid"
'MediaPlayer1.Play
'MediaPlayer1.Stop
End Sub
</pre>

If you need to code it from a Std module code then you will need to refrence the Control.
 
Upvote 0
Thanks Ivan,
Thats what I need to do: reference the control from a standard module. Each time I try, I get an error for the object or that it is un-supported.

What I want to do is build a dynamic play list engine. Load variables based upon code that re-define a few properties, so calling macros will play sounds based upon the action of the code or event.

Using your code I have a play list loaded in a dropdown that plays the WAV selected, a form button hard-coded WAV, a cell based list of WAV file names that play when selected, but have not been able to make a more universal player that can be accessed through dynamic code.

I will check out the Right-click-view-code. JSW
 
Upvote 0
Ivan,

Yes you are right, the right-click-view-code object properties did give me the full list of properties. I add the controle properties I needed. I should have known it would work just like any other control!

I am still having a problem with loading variables for the control properties in a standard module:

Sub myWAV()
MediaPlayer1.Open (mySound)
MediaPlayer1.PlayCount = myExtra
End Sub

Where mySound and myExtra are passed variables.

I tried the "MediaPlayer.MediaPlayer1" object it crashes,
if I only use "MediaPlayer1" I error out: Object required? JSW
 
Upvote 0
On 2002-08-23 18:04, Joe Was wrote:
Ivan,

Yes you are right, the right-click-view-code object properties did give me the full list of properties. I add the controle properties I needed. I should have known it would work just like any other control!

I am still having a problem with loading variables for the control properties in a standard module:

Sub myWAV()
MediaPlayer1.Open (mySound)
MediaPlayer1.PlayCount = myExtra
End Sub

Where mySound and myExtra are passed variables.

I tried the "MediaPlayer.MediaPlayer1" object it crashes,
if I only use "MediaPlayer1" I error out: Object required? JSW

Hi Joe,
because the MediaPlayer is an embeded
object in the Worksheet, hence the
underlying code in the Worksheets Code Module, the Object is not available to any
other Module, it is Private to the worksheet
code module.
So if you are working from a STD Module you will need to reference the MediaPlayers Class Interface = IMediaPlayer

So this is how it would look;<PRE><FONT color=blue>Option Explicit</FONT><FONT color=#339966>'//</FONT><FONT color=#339966>'// Joe you need to reference it as below</FONT><FONT color=#339966>'// This is how I would do it.</FONT><FONT color=#339966>'//</FONT><FONT color=blue>Dim</FONT>objMP<FONT color=blue>As</FONT> MediaPlayer.IMediaPlayer<FONT color=blue>Sub</FONT>InitializeMediaPlayer()<FONT color=blue>If</FONT>objMP Is<FONT color=blue> Nothing</FONT><FONT color=blue> Then</FONT><FONT color=blue>Set</FONT>objMP = ActiveSheet.OLEObjects("MediaPlayer1").Object<FONT color=#339966> '// OR if OLEObject on another sheet say Sheet2 (Code name) then</FONT><FONT color=#339966> 'If objMP Is Nothing Then Set objMP = Sheet2.OLEObjects("MediaPlayer1").Object</FONT><FONT color=blue>End Sub</FONT><FONT color=blue>Sub</FONT>PlaySnd()



InitializeMediaPlayer

objMP.<FONT color=blue>Open</FONT>("C:WINDOWSMEDIABach's Brandenburg Concerto No. 3.rmi")<FONT color=blue>End Sub</FONT><FONT color=blue>Sub</FONT>StopSnd()

InitializeMediaPlayer

objMP.Stop<FONT color=blue>End Sub</FONT></PRE>
_________________
Kind Regards,<font size=+2><font color="red"> I<font color="blue">van<font color="red"> F M</font color="blue">oala</font><font size=1> From the City of Sails
image.gif

This message was edited by Ivan F Moala on 2002-08-23 19:21
 
Upvote 0
Ivan,
Your so good. I have looked at this in Help and have never been able to get it to work, thanks for showing me how. JSW
 
Upvote 0

Forum statistics

Threads
1,222,151
Messages
6,164,244
Members
451,882
Latest member
Bigtop

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top