{"id":12133,"date":"2012-04-10T14:53:22","date_gmt":"2012-04-10T14:53:22","guid":{"rendered":"http:\/\/www.learnexcelmacro.com\/?p=1556"},"modified":"2022-08-06T23:54:57","modified_gmt":"2022-08-06T23:54:57","slug":"assign-macro-to-hyperlink","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2012\/04\/assign-macro-to-hyperlink\/","title":{"rendered":"Assigning Macro : How to assign macro to Hyperlink ?"},"content":{"rendered":"
[et_pb_section fb_built=”1″ _builder_version=”4.16″ da_disable_devices=”off|off|off” global_colors_info=”{}” da_is_popup=”off” da_exit_intent=”off” da_has_close=”on” da_alt_close=”off” da_dark_close=”off” da_not_modal=”on” da_is_singular=”off” da_with_loader=”off” da_has_shadow=”on”][et_pb_row _builder_version=”4.16″ background_size=”initial” background_position=”top_left” background_repeat=”repeat” global_colors_info=”{}”][et_pb_column type=”4_4″ _builder_version=”4.16″ custom_padding=”|||” global_colors_info=”{}” custom_padding__hover=”|||”][et_pb_text _builder_version=”4.17.6″ background_size=”initial” background_position=”top_left” background_repeat=”repeat” hover_enabled=”0″ global_colors_info=”{}” sticky_enabled=”0″]So far we have always seen running any Macro or Function using a Command Button. Sometimes, instead of putting a Command Button, you want to do the same operations but by using a Hyperlink in Excel. In this article, you are going to learn how to run a macro by using Hyperlink in Excel.<\/p>\n
\nStep 1. <\/strong>Select the Cell Where you want to make the Hyperlink Assign Macro to a Hyperlink<\/p><\/div><\/p>\n Step 4. <\/strong>Click Ok. \nIn the Above Code we are comparing the Cell Address and then Executing a Set of Code or Function. There is another way of doing this also. We can Compare with the Target Name and execute the Code. In the above example as i have given the Name of the Hyperlink Target as MyMacro<\/strong>. <\/p>\n [\/et_pb_text][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>\n<\/span>","protected":false},"excerpt":{"rendered":" So far we have always seen running any Macro or Function using a Command Button. Sometimes, instead of putting a Command Button, you want to do the same operations but by using a Hyperlink in Excel. In this article, you are going to learn how to run a macro by using Hyperlink in Excel. 7 […]<\/p>\n","protected":false},"author":45,"featured_media":242521,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"So far we have always seen running any Macro or Function using a Command Button. Sometimes, instead of putting a Command Button, you want to do the same operations but by using a Hyperlink in Excel. In this article you are going to learn how to run a macro by using Hyperlink in Excel.\r\n\u00a0\r\nFollow the below Simple Steps to do so:<\/strong>\r\n
\nStep 2. <\/strong>Right Click –> Hyperlink…
\nStep 3. <\/strong>Enter the Address of the Same cell where you are making the hyperlink and Give the name to the Link. See the below picture:
\n
\nStep 5. <\/strong> HyperLink is created.
\n
\nNote:<\/strong> Clicking on this Hyperlink, will do nothing because it is assigned to the same Cell Address.
\n
\nStep 6. <\/strong>Now Press Alt + F11
\nStep 7. <\/strong> Copy paste the below Code as shown in Picture<\/p>\n\nPrivate Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)\n 'Check if the Target Address is same as you have given\n 'In the above example i have taken A4 Cell, so I am\n 'Comparing this with $A$4\n \n If Target.Range.Address = \"$A$4\" Then\n 'Write your all VBA Code, which you want to execute\n 'Or Call the function or Macro which you have\n 'written or recorded.\n MsgBox \"Write your Code here to be executed\"\n Exit Sub\n End If\nEnd Sub\n<\/code><\/pre>\n
\nPrivate Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)\n 'Check if the Target Name is same as you have given\n 'In the above example i have given the Name of the HyperLink\n 'is MyMacro.\n \n If Target.Name = \"mymacro\" Then\n 'Write your all VBA Code, which you want to execute\n 'Or Call the function or Macro which you have\n 'written or recorded.\n MsgBox \"Write your Code here to be executed\"\n Exit Sub\n End If\nEnd Sub\n\n<\/code><\/pre>\n
\r\nStep 1. <\/strong>Select the Cell Where you want to make the Hyperlink\r\nStep 2. <\/strong>Righ Click --> Hyperlink...\r\nStep 3. <\/strong>Enter the Address of the Same cell where you are making the hyperlink and Give name to the Link. See the below picture:\r\n\r\n\r\nStep 4. <\/strong>Click Ok.\r\nStep 5. <\/strong> HyperLink is created.\r\n\u00a0\r\nNote:<\/strong> Clicking on this Hyperlink, will do nothing because it is assigned to the same Cell Address.\r\n\u00a0\r\nStep 6. <\/strong>Now Press Alt + F11\r\nStep 7. <\/strong> Copy paste the below Code as shown in Picture\r\n
\r\n[caption id=\"attachment_1570\" align=\"aligncenter\" width=\"300\" caption=\"Run Excel Macro by Clicking on a Hyperlink\"]<\/a>[\/caption]\r\n
\r\n\r\nPrivate Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)\r\n 'Check if the Target Address is same as you have given\r\n 'In the above example i have taken A4 Cell, so I am\r\n 'Comparing this with $A$4\r\n \r\n If Target.Range.Address = \"$A$4\" Then\r\n 'Write your all VBA Code, which you want to execute\r\n 'Or Call the function or Macro which you have\r\n 'written or recorded.\r\n MsgBox \"Write your Code here to be executed\"\r\n Exit Sub\r\n End If\r\nEnd Sub\r\n<\/code><\/pre> \r\n
\r\nIn the Above Code we are comparing the Cell Address and then Executing a Set of Code or Function. There is another way of doing this also. We can Compare with the Target Name and execute the Code. In the above Example as i have given the Name of the Hyperlink Target as MyMacro<\/strong>. \r\n\r\n
\r\n\r\nPrivate Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)\r\n 'Check if the Target Name is same as you have given\r\n 'In the above example i have given the Name of the HyperLink\r\n 'is MyMacro.\r\n \r\n If Target.Name = \"mymacro\" Then\r\n 'Write your all VBA Code, which you want to execute\r\n 'Or Call the function or Macro which you have\r\n 'written or recorded.\r\n MsgBox \"Write your Code here to be executed\"\r\n Exit Sub\r\n End If\r\nEnd Sub\r\n\r\n<\/code><\/pre> \r\n
\r\n\r\n
\r\n\r\n