+ Reply to Thread
Results 1 to 8 of 8

How do I modularize this code?

  1. #1
    Registered User
    Join Date
    05-24-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    46

    Question How do I modularize this code?

    Hi,
    I've written up some code to center the a hyperlink target on the center of the page and I want to use it on several sheets, so I figured a module is the way to go... How do I modularize this?

    Please Login or Register  to view this content.
    Last edited by nanomess; 04-04-2013 at 11:54 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,626

    Re: How do I modularize this code?

    It's event code and can't really be put in a standard module, if that's what you mean by 'modularize'.

    What you can do however is use the workbook level event SheetFollowHyperlink which goes in the ThisWorkbook module.

    It will be triggered when a hyperlink on any worksheet in the workbook is clicked.

    Here's it's code stub, where Sh is the sheet that the hyperlink that was clicked is on and Target is the hyperlink clicked.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    05-24-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: How do I modularize this code?

    Hi,
    Is it possible to have an example file posted? Bit of a vba dummy, so learn better from example.

    Additionally, what is the best way to exclude certain hyperlinks from being affected by this code? For example, I might want a hyperlink on C5 on Sheet1 not to be affected by this centering code.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,626

    Re: How do I modularize this code?

    Can you attach a workbook with some sample data?

  5. #5
    Registered User
    Join Date
    05-24-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: How do I modularize this code?

    No problem, just give me a few minutes and thank you!

  6. #6
    Registered User
    Join Date
    05-24-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: How do I modularize this code?

    I've attached an example file where the hyperlink targets are all top left aligned.

    So I have two issues:
    1. How do I use ThisWorkbook module to avoid repeating this hyperlink code on both Sheet1 and Sheet2?
    2. How do I exclude cells (or include cells) to be affected by this alignment? For example, on sheet 1 how can I exclude "Link B" from the hyperlinks that are affected by this?
    Attached Files Attached Files

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,626

    Re: How do I modularize this code?

    Put this in the ThisWorkbook module.
    Please Login or Register  to view this content.
    I realise you'll probably want to exclude other links and a simple If, or multiple Ifs, might not be adequate for that.

    So another method would need to be used to determine which links to exclude.

  8. #8
    Registered User
    Join Date
    05-24-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: How do I modularize this code?

    You've been a real help! Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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