• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Playing a Window Media Player's playlist in Excel|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Playing a Window Media Player's playlist in Excel|VBA & Macros|Excel Forum|My Online Training Hub

Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosPlaying a Window Media Player's pla…
sp_PrintTopic sp_TopicIcon
Playing a Window Media Player's playlist in Excel
Page: 12Jump to page
Avatar
julian
Member
Members
Level 0
Forum Posts: 79
Member Since:
December 12, 2016
sp_UserOfflineSmall Offline
1
December 12, 2016 - 6:24 pm
sp_Permalink sp_Print sp_EditHistory

abc.pngImage Enlarger

Hi Mynda,

I have an Excel file embedded Window Media Player Control using a pivot table slicer to populate the selected files on column A as the snapshot attached. I also wrote a VBA in a hope to play the file in the list one after another.

Sub test()
Range("A2").Select
Do While Not IsEmpty(ActiveCell)
Text1 = ActiveCell.Value
WindowsMediaPlayer2.URL = Text1
WindowsMediaPlayer2.Controls.Play

' how to continue the next until the previous one has been over?

Selection.Offset(1, 0).Select
Loop
End Sub

Unfortunately, after running through the loop WindowMedia Player 1 alway just play the last file only. Could you please spare some time to take a look at this case and help me correct it? I would appreciate it.
Best regards,

Julian Chen

sp_PlupAttachments Attachments
  • sp_PlupImage abc.png (23 KB)
sp_AnswersTopicSeeAnswer See Answer
Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1800
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
December 12, 2016 - 8:25 pm
sp_Permalink sp_Print sp_EditHistory

Hi Julian,

I think you have to build the playlist first, then you start play.

Try:

Sub test()
Dim NewFile as Variant
Range("A2").Select
Do While Not IsEmpty(ActiveCell)
WindowsMediaPlayer1.playlistCollection.getByName("MyNewPlaylist")
WindowsMediaPlayer1.currentPlaylist.Clear
Text1 = ActiveCell.Value
Set newFile = WindowsMediaPlayer1.newMedia(Text1)
WindowsMediaPlayer1.currentPlaylist.insertItem 0, newMedia
Selection.Offset(1, 0).Select
Loop
'the playlist is created, play it
WindowsMediaPlayer1.Controls.Play

End Sub

Avatar
julian
Member
Members
Level 0
Forum Posts: 79
Member Since:
December 12, 2016
sp_UserOfflineSmall Offline
3
December 13, 2016 - 11:36 am
sp_Permalink sp_Print

Hi Catalin,

 Thanks for your prompt reply. I copied your code into my Sub Worksheet_PivotTableUpdate function as it was triggered by Pivot Table update then changed the initial cell to "A33" as listed below. However, after running the code the program would be stuck on line 8 with a run-time error 424 - 'Object required". Could you please check it out what's missing?

Regards,

Julian 

 Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
 Dim NewFile As Variant
 Range("A33").Select
 Do While Not IsEmpty(ActiveCell)
 WindowsMediaPlayer1.playlistCollection.getByName ("MyNewPlaylist")
 WindowsMediaPlayer1.currentPlaylist.Clear
 Text1 = ActiveCell.Value
 Set NewFile = WindowsMediaPlayer1.newMedia(Text1)
 WindowsMediaPlayer1.currentPlaylist.insertItem 0, newMedia
 Selection.Offset(1, 0).Select
 Loop
 'the playlist is created, play it
 'WindowsMediaPlayer1.Controls.Play
 
End Sub        

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1800
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
4
December 13, 2016 - 2:56 pm
sp_Permalink sp_Print

Dim NewFile as Object, instead of variant, this should be the problem.

Avatar
julian
Member
Members
Level 0
Forum Posts: 79
Member Since:
December 12, 2016
sp_UserOfflineSmall Offline
5
December 13, 2016 - 3:46 pm
sp_Permalink sp_Print

Hi Catalin,

The same problem "Object required" still exists. Does it need to create a playlistarray instead?

Regards,

Julian

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1800
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
6
December 13, 2016 - 4:41 pm
sp_Permalink sp_Print

Can you upload a sample file?

Avatar
julian
Member
Members
Level 0
Forum Posts: 79
Member Since:
December 12, 2016
sp_UserOfflineSmall Offline
7
December 14, 2016 - 11:16 am
sp_Permalink sp_Print

Hi Catalin,

Here you are the attached file. There are 3 Window Media Players embedded in, Please check the tab with name "Media". The rest two works well. Sorry again for bothering you so much.

 

Best regards,

 

Julian

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1800
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
8
December 14, 2016 - 2:41 pm
sp_Permalink sp_Print

Try changing these 2 lines:

Dim NewFile As Variant
 

NewFile = WindowsMediaPlayer1.newMedia(Text1)

 

Or, you can try this version:

 

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
 Dim NewFile As Variant

Dim Playlist As IWMPPlaylist
Set Playlist = WindowsMediaPlayer1.newPlaylist("MyNewPlayList", "")
 Range("A33").Select

'the following 2 lines were inside the loop, which was wrong... we don't have to clear the list at each loop

 WindowsMediaPlayer1.playlistCollection.getByName ("MyNewPlaylist")
 WindowsMediaPlayer1.currentPlaylist.Clear

 Do While Not IsEmpty(ActiveCell)
 Text1 = ActiveCell.Value
  NewFile = WindowsMediaPlayer1.newMedia(Text1)
 WindowsMediaPlayer1.currentPlaylist.insertItem 0, newMedia
 Selection.Offset(1, 0).Select
 Loop
 'the playlist is created, play it
 'WindowsMediaPlayer1.Controls.Play

 
End Sub      

Or, you can try adding items to the new playlist created, then set the playlist as current, instead of clearing the current playlist and adding new items:

Do while...

Playlist.appendItem WindowsMediaPlayer1.newMedia(Text1)

Loop
WindowsMediaPlayer1.currentPlaylist = Playlist

WindowsMediaPlayer1.Controls.Play

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1431
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
9
December 14, 2016 - 4:13 pm
sp_Permalink sp_Print

Hi Julian

Try this amended code (original code from Catalin above). Tested and working for me.

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Dim NewFile As Variant
Dim Playlist As IWMPPlaylist
Set Playlist = WindowsMediaPlayer1.newPlaylist("MyNewPlayList", "")
Range("A33").Select
WindowsMediaPlayer1.playlistCollection.getByName ("MyNewPlaylist")
WindowsMediaPlayer1.currentPlaylist.Clear
Do While Not IsEmpty(ActiveCell)
Text1 = ActiveCell.Value
'NewFile = WindowsMediaPlayer1.newMedia(Text1)
Set NewFile = WindowsMediaPlayer1.mediaCollection.Add(Text1)
WindowsMediaPlayer1.currentPlaylist.insertItem (WindowsMediaPlayer1.currentPlaylist.Count), NewFile
Selection.Offset(1, 0).Select
Loop

'the playlist is created, play it
WindowsMediaPlayer1.Controls.Play

End Sub

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1431
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
10
December 14, 2016 - 4:33 pm
sp_Permalink sp_Print

Hi Julian

Attached is my own sample playlist.

Hope this helps.

Cheers

Sunny

Avatar
julian
Member
Members
Level 0
Forum Posts: 79
Member Since:
December 12, 2016
sp_UserOfflineSmall Offline
11
December 15, 2016 - 1:53 pm
sp_Permalink sp_Print

Hi Catalin / SunnyKow's :

Let me report my test results as follows:

I' m sorry to say all the solutions provided below were failed and I'm not sure did it has something with my 64-bit operating sytem. In order to get support memory amounts over 4 GB for Power query and DAX running I've installed my Excel 2013 and PowerBI desk in 64-bit versions. If this is the case, how the VBA script can be modified?

Scripts from Catalin - got the same error message "Object does'nt suppport this property or method" and stuck on the line in bold font type

(1).

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
  Dim NewFile As Variant
  NewFile = WindowsMediaPlayer1.newMedia(Text1)
  Range("A33").Select
  Do While Not IsEmpty(ActiveCell)
  WindowsMediaPlayer1.playlistCollection.getByName ("NewFile")
  WindowsMediaPlayer1.currentPlaylist.Clear
  Text1 = ActiveCell.Value
  Set NewFile = WindowsMediaPlayer1.newMedia(Text1)
  WindowsMediaPlayer1.currentPlaylist.insertItem 0, newMedia
  Selection.Offset(1, 0).Select
  Loop
  'the playlist is created, play it
  'WindowsMediaPlayer1.Controls.Play
End Sub

(2).

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
 Dim NewFile As Variant

Dim Playlist As IWMPPlaylist
Set Playlist = WindowsMediaPlayer1.newPlaylist("MyNewPlayList", "")
 Range("A33").Select

'the following 2 lines were inside the loop, which was wrong... we don't have to clear the list at each loop

 WindowsMediaPlayer1.playlistCollection.getByName ("MyNewPlaylist")
 WindowsMediaPlayer1.currentPlaylist.Clear

 Do While Not IsEmpty(ActiveCell)
 Text1 = ActiveCell.Value
  NewFile = WindowsMediaPlayer1.newMedia(Text1)
 WindowsMediaPlayer1.currentPlaylist.insertItem 0, newMedia
 Selection.Offset(1, 0).Select
 Loop
 'the playlist is created, play it
 'WindowsMediaPlayer1.Controls.Play

Script from SunnyKow's fixed code - got the error message: "Method 'add' of object ' IWMPMedia Collectio2' failed" and stuck on the line in bold font type

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Dim NewFile As Variant
Dim Playlist As IWMPPlaylist
Set Playlist = WindowsMediaPlayer1.newPlaylist("MyNewPlayList", "")
Range("A33").Select
WindowsMediaPlayer1.playlistCollection.getByName ("MyNewPlaylist")
WindowsMediaPlayer1.currentPlaylist.Clear
Do While Not IsEmpty(ActiveCell)
Text1 = ActiveCell.Value
'NewFile = WindowsMediaPlayer1.newMedia(Text1)
Set NewFile = WindowsMediaPlayer1.mediaCollection.Add(Text1)
WindowsMediaPlayer1.currentPlaylist.insertItem (WindowsMediaPlayer1.currentPlaylist.Count), NewFile
Selection.Offset(1, 0).Select
Loop

'the playlist is created, play it
WindowsMediaPlayer1.Controls.Play

End Sub

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1431
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
12
December 16, 2016 - 1:20 am
sp_Permalink sp_Print

Hi Julian

The worksheet I attached earlier (with Catalin's code) works fine with me. No errors at all.

I wonder if any other members encountered the same error as yours.

Anyway, I have attached another version that I have. The codes are different. Hopefully it will work for you this time.

Sunny

sp_AnswersTopicAnswer
Answers Post
Avatar
julian
Member
Members
Level 0
Forum Posts: 79
Member Since:
December 12, 2016
sp_UserOfflineSmall Offline
13
December 16, 2016 - 1:00 pm
sp_Permalink sp_Print

Hi SunnyKow,

Just tried run your file on my computer and it worked well. Therefore, I would modify my script based on your version later on. By the way, Just wonder if you have ever tried to play the transcripts files together with the videos synchronously also using VBA script? I think it's worth a trial. Any way, Thanks for your early Christmas gift. You are my this year's Santa Claus.

Best regards,

Julian

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1431
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
14
December 16, 2016 - 1:16 pm
sp_Permalink sp_Print

Hi Julian

Happy to know it is working now.

"Just wonder if you have ever tried to play the transcripts files together with the videos synchronously also using VBA script?"

What transcript files are you referring to?

Avatar
julian
Member
Members
Level 0
Forum Posts: 79
Member Since:
December 12, 2016
sp_UserOfflineSmall Offline
15
December 16, 2016 - 2:19 pm
sp_Permalink sp_Print

It's about SubRip file format with (.srt) extension or simply a plain text file showing what was said (ii.e. subtitle or caption) in a video / movie....

 

 

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1431
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
16
December 16, 2016 - 5:12 pm
sp_Permalink sp_Print

Hi Julian

I can get the SubRip file format to run with the VLC media player (not from Excel) but not on WMP.

I think I need to download some codec. I will set this as my 2017 new year resolution to learn more about SubRip file format.

Sunny

Avatar
julian
Member
Members
Level 0
Forum Posts: 79
Member Since:
December 12, 2016
sp_UserOfflineSmall Offline
17
December 17, 2016 - 12:17 am
sp_Permalink sp_Print

Hi Sunny,

Just came out two more findings for your reference: Both simplified Chinese characters and m4a file extensions could not be recognized when you Set sMedia = WindowsMediaPlayer2.mediaCollection.Add(SelVideo). And it's very nice to hear your new year resolution. I believe you must have had a very fruitful year 2016. I also wish you Merry Christmas and a happy new year soon in next two weeks. Thank you very much again for the wonderful gift you gave me.

 

Best regards,

 

Julian

Avatar
julian
Member
Members
Level 0
Forum Posts: 79
Member Since:
December 12, 2016
sp_UserOfflineSmall Offline
18
January 31, 2017 - 7:14 am
sp_Permalink sp_Print

Hi Sunny,

Regarding the script as listed below you provided for me last time, could you please do me one more favor by adding a loop to restart the playlist when it comes to the end? Tahnks advance.

Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
SelVideo = "Start"
    Set sPlayList = WindowsMediaPlayer2.playlistCollection.newPlaylist("MyPlayList")
    WindowsMediaPlayer2.currentPlaylist = sPlayList
   
    '1 row above the playlist
    ctr = 32
    Do While SelVideo <> ""
        ctr = ctr + 1
       
        'Add the song/video name from the current row
        SelVideo = Worksheets("Media").Cells(ctr, 1).Value
       
        'Exit if end of playlist
        If SelVideo = "" Then Exit Do
       
        Set sMedia = WindowsMediaPlayer2.mediaCollection.Add(SelVideo)
        WindowsMediaPlayer2.currentPlaylist.insertItem (WindowsMediaPlayer2.currentPlaylist.Count), sMedia
    Loop
   
    'Play the playlist
    WindowsMediaPlayer2.fullScreen = False
    'WindowsMediaPlayer2.Width = 550 '400 '260
    'WindowsMediaPlayer2.Height = 380 '355 '220
    WindowsMediaPlayer2.Controls.Play
End Sub

Julian

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1431
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
19
February 1, 2017 - 1:22 am
sp_Permalink sp_Print

Hi Julian

Add this to your code:

'Play the playlist
WindowsMediaPlayer2.settings.setMode "Loop", True
WindowsMediaPlayer2.fullScreen = False

BTW I have learned that WMP does not support .srt (subtitle) but WMP Classic does. Since I don't have WMP Classic, I am now using VLC instead and it looks OK although I don't use subtitle myself. (My 2017 New Year resolution completed Cool).

Hope this helps.

Sunny

Avatar
julian
Member
Members
Level 0
Forum Posts: 79
Member Since:
December 12, 2016
sp_UserOfflineSmall Offline
20
February 1, 2017 - 7:47 am
sp_Permalink sp_Print

Hi Sunny,

Thanks again for your great support. Furthermore, to my surprise you were that serious to make your commitment and completed it so quickly. You are really awesome. I do admire your resolution.

Best regards,

Julian

Page: 12Jump to page
sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 170
Currently Online: Mynda Treacy, Christian Huapaya, Laxmi Praveen
Guest(s) 3
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1431
Anders Sehlstedt: 845
Velouria: 574
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 213
A.Maurizio: 202
Aye Mu: 201
Jessica Stewart: 185
Newest Members:
Vicky Otosnika
Abhishek Singh
Kevin Sojourner
Kara Weiss
And Woox
Armani Quenga
moshood bello
annelies b
James1989
lucy gilmour
Forum Stats:
Groups: 3
Forums: 24
Topics: 6045
Posts: 26524

 

Member Stats:
Guest Posters: 49
Members: 31492
Moderators: 2
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Riny van Eekelen
© Simple:Press —sp_Information
  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
 
  • About My Online Training Hub
  • Contact
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Copyright © 2023 · My Online Training Hub · All Rights Reserved

Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.

Download A Free Copy of 100 Excel Tips & Tricks

excel tips and tricks ebook

We respect your privacy. We won’t spam you.

x