• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

hyperlink + macro at the same time?

JC

New Member
Can we add a hyperlink to an inserted icon, and a macro at the same time?


In my file, the users click on the icon to go to the different sheet, in the same workbook. That's O.K.


Now I just want to add a sound macro to the icon, so when the user click on the icon, they hear the sound and go to the right place. When I added the macro to the icon that already contains the hyperlink, the macro does not work, only the hyperlink. When I remove the hyperlink, then the macro works perfectly.


Where is the problem?


Thank you very much for your help
 
Hi Narayan,


Thank you very much for your information.


I think this can help, at least I will try.


Later I will let you know.


Best,


JC
 
Hi Narayan,


Sorry for the late answer.


Unfortunately,nothing works properly.


Everything remained as before: when you click on the inserted icon in the spreadsheet#1, which in turn has added a hyperlink, you go to the right place, the spreadsheet#2. If I add a sound macro to the same icon, when you click it, runs only the hyperlink.

When you remove the hyperlink, and add only the macro, the macro runs perfectly.


So the problem remains.


Just in case, here is the sound macro:


Declare PtrSafe Function PlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal wavFile As String, ByVal lNum As Long) As Long


Sub Play_Sound()

Call PlaySound("C:WindowsMediachimes.wav", 0)

End Sub


Any help will be greatly appreciated


Best regards,


JC
 
Hi

If your Hyperlink in cell A1, write this code in the module of your worksheet

[pre]
Code:
Private Declare PtrSafe Function PlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal wavFile As String, ByVal lNum As Long) As Long

Private Sub Play_Sound()

PlaySound "C:WindowsMediachimes.wav", 0
End Sub

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)

If Target.Range.Address = "$A$1" Then Play_Sound
End Sub
[/pre]

Tested in a worksheet.

Regards
 
Hi Mercatog,


I did it, but nothing!


The hyperlink works, not the sound!


Thank you for your answer!


Regards,


JC
 
Hi, JC!


First of all welcome to Chandoo's website Excel forums. Thank you for your joining us and glad to have you here.


As a starting point I'd recommend you to read the three first green sticky topics at this forums main page. There you'll find general guidelines about how this site and community operates (introducing yourself, posting files, netiquette rules, and so on).


Among them you're prompted to perform searches within this site before posting, because maybe your question had been answered yet.


Feel free to play with different keywords so as to be led thru a wide variety of articles and posts, and if you don't find anything that solves your problem or guides you towards a solution, you'll always be welcome back here. Tell us what you've done, consider uploading a sample file as recommended, and somebody surely will read your post and help you.


And about your question...


Consider uploading a sample file as indicated on second green sticky post. Preferably it should contain both implementation intents, yours and mercatog's, just to reproduce exactly the issue you might be experiencing.


Regards!
 
Hi, JC!


Regarding:

http://chandoo.org/forums/topic/welcome-to-phd-forums/page/11#post-39045

that I didn't answer at its origin because it wasn't the proper place, I should say that you're right, you've only got a few minutes to live and many of them are gone yet, so why not uploading the asked file first and then you can go on burning yourself with fire, damn sinner?


Regards!


PS: BTW, I think I couldn't forgive you -despite of the fact if I wanted to-, remember that to err is human but to forgive is divine.
 
Hi Gentlemen,


Unfortunately, I need to travel to much, so not to much time to be quiet and have the possibilty of learning from you.


Returning to my old question. Mercatog, your option is working 100%, thank you, but the way you did is a little different, and is not exactly what I need.


I think here is not need of uploading any file, due of the simplicity of the case.


Let me explain:


- open a new and empty document in Excel (I am using 2010),

- in any place (this is very important, we can not attach the picture or icon to any specific direction, the picture or icon need to be where ever the final user wants it to be) or cell of Sheet1, click Insert from the Top Toolbar, select Picture, and click in any picture/icon you want,

- in my case, I have an small catalog with different icons, so I inserted an icon of the arrow,

- adding an hyperlink to this icon, to go to the Sheet2,

- and finally, adding a sound macro I provided, to the same icon.


That is all.


What we need now is, that when the user clicks on this icon, the user can hear the sound while being routed to the Sheet2.


All the time when I tried to do something, the hyperlink seeming to have higher priority is executed, not the macro.


Any help will be greatly appreciated,


JC
 
Hi JC ,


I wonder why you want this specific mechanism to work , when the hyperlink action of going to another location in the current workbook can also form part of the Play_Sound macro , or when you can call another macro to do the navigation.


Any particular reason ?


Narayan
 
Hi Narayank991,


Thank you very much for your suggestion.


I had not really thought about this possibility, but the insistence to use this mechanism, is because my project is composed of more than 100 sheets in the same file, and they all use the icons with hyperlinks, as the easiest way to navigate from one page to another. I simply want to add sound, like a small detail to make the system more dynamic.


I may not have understood exactly your suggestion, but:


- how to make the same icon takes the user from one page to another, according to the logic of the system, in a file of more than 100 pages, adding a motion macro(which would make the hyperlink function)within the sound macro, without the need to create a macro for each specific movement?


Sir Ninja, please forgive my ignorance, and do not cut my head, at least serves to make silly questions!


Thank you,


JC
 
Hi JC ,


Forget about the Ninja business , we are all learners !


The moment you assign a macro to a picture , you can use the macro to navigate to wherever you want to go within the workbook , by using the Activate and Select methods within the macro. Of course , if you already have the hyperlinks existing within the workbook , I agree it will be a pain to now introduce a 100 macros , since each of them will have to go to a different location within the workbook.


Can you try the following ?


Suppose in a module you have your Play_Sound macro with its declaration as follows :

[pre]
Code:
Declare Function PlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal wavFile As String, ByVal lNum As Long) As Long

Sub Play_Sound()
Call PlaySound("C:WindowsMediachimes.wav", 0)
End Sub
Suppose in the ThisWorkBook section , you have this procedure :

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Call Play_Sound
End Sub
[/pre]
Now , when you click on your icon , IF YOUR DESTINATION LOCATION IS NOT ALREADY THE ACTIVE CELL , i.e. if the cursor is not already in the destination cell , then you should hear the sound , and the hyperlink should take you to the destination cell.


Narayan
 
Back
Top