+ Reply to Thread
Results 1 to 34 of 34

Repeat code in double-click event

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Repeat code in double-click event

    Hello everyone
    I have a code but I will not be able to post the entire code as the owner of the code told me not to publish it (Sorry for that)
    The code is working from ThisWorkbook module
    Please Login or Register  to view this content.
    It is supposed to play mp3 file when double click in the cell. It is working well with no problem
    What I am trying to modify is to make the mp3 file repeated twice ( I mean to run this event twice instead of once)
    I tried to declare a variable i and to make a loop of 2 iterations and also added line of waiting, but when double click the cell, the file is played once not twice. Any idea how to make it repeat for twice?

    Posted here too
    http://www.eileenslounge.com/viewtopic.php?f=30&t=35401
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,431

    Re: Repeat code in double-click event

    One way appears to build a play list

    https://stackoverflow.com/questions/...es-using-loops
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Repeat code in double-click event

    Yes I could do that point but I faced problems with this line
    Please Login or Register  to view this content.
    Also the file repeated with no pause in between, as I need to let some pauses between the pay process for the same mp3 file.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,431

    Re: Repeat code in double-click event

    Could you not play a blank sound file in between?

    No idea what that code is, what it is suppose to do or what the error is. You need to provide more detail

  5. #5
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,180

    Re: Repeat code in double-click event

    Hi Yasser

    Have no idea of file setup...This is only a sample that allows looping of song|sound
    Perhaps you can incorporate...Have only made use of one sound in [A1] for sample...
    Attached Files Attached Files
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Repeat code in double-click event

    Thanks a lot Sintek. That worked fine.
    In fact, I need to modify the existing code to do the same .. for more details this is the sub that doesn't work when using newMedia approach
    Please Login or Register  to view this content.

  7. #7
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,180

    Re: Repeat code in double-click event

    What about putting the call highlight outside of loop...

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Repeat code in double-click event

    Yes I tried that
    The following succeed to some extent
    Please Login or Register  to view this content.
    Now this solved the problem of repeating the mp3 file but the problem with HighLightCell sub .. It works but I need to make it work for twice too. As splash or blinking

  9. #9
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,180

    Re: Repeat code in double-click event

    Seems you are always making highlight True so the effect does not get reset...
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Perhaps incorporate...
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by sintek; 09-21-2020 at 04:00 AM.

  10. #10
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Repeat code in double-click event

    This doesn't work for me .. Sorry for that
    Generally thanks a lot for your code that you provided. I think this will be easier to adapt it instead.

  11. #11
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,180

    Re: Repeat code in double-click event

    Works here...just changed to interior and not font to see effect
    Attached Files Attached Files
    Last edited by sintek; 09-21-2020 at 04:14 AM.

  12. #12
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,180

    Re: Repeat code in double-click event

    Also, with your initial code in Post 1...

    This works...
    Please Login or Register  to view this content.

  13. #13
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Repeat code in double-click event

    In fact, I need the blinking to be at the same time when the file is played. This is what the original code do.

  14. #14
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Repeat code in double-click event

    I have to put the whole code to clarify the issue well (I hope the owner wll forgive me)
    Attached Files Attached Files

  15. #15
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,180

    Re: Repeat code in double-click event

    Surely if cell must blink while file is playing then the blinking code must be in a loop of its own...
    On Off On Off On Off etc until file finishes playing..
    Last edited by sintek; 09-21-2020 at 04:32 AM.

  16. #16
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Repeat code in double-click event

    You need to download file "1sec.mp3" from "http://www.minidisc.org/charman/downloads.html" and place in SFOLDER (as noted in comment) and then you can run the code.

    Code on ThisWorkbook module :
    Please Login or Register  to view this content.
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  17. #17
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Repeat code in double-click event

    Amazing my friend.
    That's exactly what I am trying to achieve for since some days ago.
    Thank you very much.

  18. #18
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Repeat code in double-click event

    You are welcome Yasser, thanks for reps added.

    Regards

  19. #19
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Repeat code in double-click event

    One point .. Is it possible to use the original code so as to be able to play list of files in column A and stop them if I wish ..?

  20. #20
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Repeat code in double-click event

    Yes, I think so.
    You need to keep adding .currentPlaylist.appendItem XXX (adding one outer loop until all the files on column A have been added, of course by adding the silent sound file between)
    Then you need to modify the Sub wmp_CurrentItemChange(ByVal pdispMedia As Object), by examining wmp.currentMedia.SourceUrl you need to shift rngCurrent (or the highlighted cell position is not updated) and then highlight this cell.
    For stopping, there will be no problem, just use your (adjusted) Sub StopPlaying, it'll be fine.

    Sorry, I'm still busy with real life now. I had my spare time from Saturday to Monday, and tommorrow I start to be busy again, so I hope you can modify the code by yourself.
    I'll check the progress if I have my spare time again.

  21. #21
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Repeat code in double-click event

    Thanks a lot. Take your time and at any time,please consider that point. I appreciate a lot your help.

  22. #22
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Repeat code in double-click event

    I tried to merge both codes and it works with great extent
    Please Login or Register  to view this content.
    But when playing all the files, I encountered uncorrect behaviour as for highlighting the cells .. How can I modify the existing code so as to make only the cell that is played to be affected and after finishing it, the cell would be restored to its original state?

  23. #23
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Repeat code in double-click event

    Not too sure what you want, but try this code.

    Since I see there is "Sub Workbook_SheetActivate(ByVal Sh As Object)" in your code, so to avoid confusing, I move the code from ThisWorkbook code module to Sheet1 code module.

    Code in Sheet1 module :
    Please Login or Register  to view this content.
    Current behaviour :
    - to start playing, is triggered by double click on a cell
    - to stop playing, is by run (press Alt F8) "Sheet1.StopIt" sub
    - to pause/resume playing, is by run (press Alt F8) "Sheet1.PauseResumeIt" sub
    - wmp will play to next song (next cell) if current song has been played, and goto first song (first cell) if the next cell is empty

    You will need to attach the Sub StopIt() and PauseResumeIt() by yourself, maybe to a Command Button.
    The code is also not including the monitoring wmp status on cell Z1, you can add this by yourself.

    Still busy, if there is further question, probably on weekend I have a spare time again to look at, not promise.

  24. #24
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Repeat code in double-click event

    Never mind my bro. I am not in hurry so take your time.

    To explain the whole issue, I will exapplain in more details
    I am trying to design a workbook for my students .. The workbook has several worksheets (each sheet for a unit) >> so I don't want to put the code in Worksheet modules (Would be better if put in class module or standard module or ThisWorkbook module .. for that reason I will work on several sheets

    In each sheet I have the words or phrases in column A so I need first : to play all the words one by one (letting waiting time in between) and to be able to stop at any momnet
    Second to be able to double click any cell and play that cell only.

    ** When trying the last code, I noticed when I double click a cell it is played and the next words are played too and that is not desired
    What I have posted is working great to great extent. Only one problem with highlighting the cells (When playing all the mp3 files)
    so if possible I would like to edit the code I posted in my previous reply as this is near to my imagination.

  25. #25
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Repeat code in double-click event

    Still confused, you said that there are 2 actions :
    - to play all the words one by one (letting waiting time in between) and to be able to stop at any momnet
    - Second to be able to double click any cell and play that cell only.

    Of course one action (double click) cannot run 2 different actions, so probably one action is triggered by doubleclick, and the other one by a command button ?

    Anyway, since you said your macro is worked in great extent and only need the code to highlighting the cell, here is one approach :
    - before highlight /unhighlight a cell, compare the string from wmp.currentMedia.SourceUrl
    - if it is = strSilentSoundFile, then unhighlight that cell (no need to move)
    - it not, then extract the name only (using mid() function, by removing SFOLDER at front and ".mp3" and end), then using Range(PLAY_LIST_RANGE_ADDR).Find() method, search for this string, and then Set rngCurrent = this founded range, then you can proceed with existing highlight /unhighlight code

  26. #26
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Repeat code in double-click event

    I am confused .. I have used F8 to follow the code but didn't find a clue to the problem

    To explain the problem:
    Open the excel file >> try to double click the cell A5 for example (this part is perfect and the cell is played and highlighted without any problem at all)
    Then try to run the macro "StartPlaying" and notice that the first cell A1 is played and hihglighted and at the same time the cell A5 (which double-clicked in the previous step is highlighted too with cell A1) ..
    I know may this seems weird problem and may be trivial but I would like to get rid of it.

  27. #27
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Repeat code in double-click event

    Quote Originally Posted by YasserKhalil View Post
    .. I have used F8 to follow the code but didn't find a clue to the problem
    No, it won't work with F8, you call next song from event wmp_PlayStateChange :
    Please Login or Register  to view this content.
    Since this is an event sub, it is called only when the event is occurred, just like event "Sub Worksheet_Change(ByVal Target As Range)", you cannot trace this event, because this sub is only called when the event is fired. You can place the "Stop" statement at the beginning of the sub and then trace from there.

    I make this code with same logic with your original code using wmp_PlayStateChange() only, so not using wmp_CurrentItemChange() which in turn cannot use the playlist method like my code before.

    Code on ThisWorkbook module :
    Please Login or Register  to view this content.

  28. #28
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Repeat code in double-click event

    That's amazing materpiece of code. Thank you very much my friend
    I appreciate a lot your interest to solve that issue completely.

  29. #29
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Repeat code in double-click event

    You are welcome, glad I can help you, and many thanks for reps.

    Regards

  30. #30
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,180

    Re: Repeat code in double-click event

    So happpy you got it all sorted Yasser...

    Tx for rep +...

  31. #31
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Repeat code in double-click event

    Hello again and sorry for disturbing you
    In the event
    Please Login or Register  to view this content.
    I have added a part that enables the student to spell the words and this is the added part
    Please Login or Register  to view this content.
    I faced a problem of how to remove the appended files as when I double-click in column B the code works fine, then when double-click another cell, the code repeats the letters of the previous word plus the new word. How can I remove the appended items ..? I tried to use Set itm= nothing before and after the loop .. but the same
    I tried also to set wmp to nothing but in that case nothing is played as for spelling the letters.

  32. #32
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Repeat code in double-click event

    Maybe :
    Please Login or Register  to view this content.

  33. #33
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Repeat code in double-click event

    Thank you very much. That masterpiece of code is really amazing and will help a lot of students to study English in an easy way.
    Best and Kind Regards

  34. #34
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Repeat code in double-click event

    You are welcome, happy teaching then.

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Worksheet double click event with more than one code
    By abjac in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-15-2020, 11:55 AM
  2. [SOLVED] Double Click Event - help me to undersatand what the code is doing
    By MissDB in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-09-2016, 07:48 AM
  3. [SOLVED] Before double click event with if statements (Double clicking blank cell stops bdc firing)
    By camdenpars in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-27-2014, 09:03 AM
  4. Click v double click event code
    By Greg J in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-09-2014, 04:08 AM
  5. Double click event
    By CARONTE in forum Excel General
    Replies: 1
    Last Post: 06-14-2009, 03:02 AM
  6. double click event
    By DTrain9481 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-10-2009, 12:41 PM
  7. userform label double-click goes to click event
    By John Paul Fullerton in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-19-2006, 01:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1