+ Reply to Thread
Results 1 to 6 of 6

running a macro from hyperlink

  1. #1
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    running a macro from hyperlink

    I found on the internet a script to run a macro from a hyperlink. See script below.
    I created a hyperlink in A1 to A1 (see picture below), but the MsgBox does"t appear if I click the hyperlink.
    I have no idea why. Does anybody know what I might be doing wrong?

    Please Login or Register  to view this content.
    example.jpg

  2. #2
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: running a macro from hyperlink

    I found the problem.
    I put the script into a module. That doesn't work.
    The script needs to go into the scripting box of the Sheet (in Microsoft Excel Objects) that contains the hyperlink.

  3. #3
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: running a macro from hyperlink

    I've never done it but as what's in cell A1?

    Wait.

    You can refer to a macro but the macro MUST be in the VBAProject of the workbook NOT the VBAProject of the skeet.

    And you will have to write the macro sometjhing like

    Please Login or Register  to view this content.
    This was done out of hand so you'll have to check for syntax errors, but this is main idea
    Last edited by Keebellah; 10-22-2015 at 07:53 AM. Reason: info
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: running a macro from hyperlink

    I just wrote and tested something:

    Place the code below in a (new) module and run 'runAmacro'
    Please Login or Register  to view this content.
    A hyperlink won't work for this in any way.

    You can create an event like right click on Cell A1 to run the macro or place a button on the sheet or attache the macro to the QAT ribbon

  5. #5
    Valued Forum Contributor
    Join Date
    02-21-2010
    Location
    Tokyo, Japan
    MS-Off Ver
    Excel 2007
    Posts
    502

    Re: running a macro from hyperlink

    Keebellah, try my macro. It is working perfect as long as the macro is in the VBAproject of the sheet.
    The hyperlink in the cell doesn't need to point to anywhere. But since you have to give it a destination you just point it to itself.
    The hyperlink is then used to execute the macro.

    One can use the cell address like in my example above or by using cell content of the hyperlinked cell as in the example below.
    These are just two examples. Once you have this basic framework working many things can be implemented.

    Please Login or Register  to view this content.
    Last edited by dschmitt; 10-22-2015 at 08:59 PM.

  6. #6
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: running a macro from hyperlink

    True, mine was just a quick-and dirty.
    I have some variations and extra functionality in some code I wrote earlier but I guess the OP is not waiting for that

+ 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] How to prevent worksheet code from running while Module Macro is running:
    By Chad Bateman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-11-2015, 09:26 AM
  2. Issue running VBA code from Hyperlink
    By toddnicholson in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-13-2014, 02:05 PM
  3. [SOLVED] Excel 2010 Create a macro to check if cell contains hyperlink then apply hyperlink style
    By chasidar in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-12-2013, 04:48 AM
  4. Macro to hide/unhide cells not running or running slow
    By mbp727 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-17-2013, 04:22 PM
  5. Running code by clicking on a hyperlink cell
    By matpj in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-29-2006, 09:30 AM
  6. [SOLVED] Intra-workbook hyperlink: macro/function to return to hyperlink ce
    By marika1981 in forum Excel General
    Replies: 3
    Last Post: 05-06-2005, 01:06 AM
  7. [SOLVED] Running a Macro from a Hyperlink
    By Rich in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-20-2005, 02:06 AM

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