VBA Code - Multiple Hyperlinks to Hidden Sheets and External Items (Error 5)

ias2211

New Member
Joined
Mar 3, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a spreadsheet that has hyperlinks in column A and column H.

The hyperlinks in column A directs you to a website outside of the workbook. But, the columns in H direct to hidden sheets within the workbook. In addition, each of the hidden sheets are coded with the following script so that when you leave the tab it disappears.

Private Sub Worksheet_Deactivate()
Me.Visible = xlSheetHidden
End Sub

I used the script below for the hyperlinks in column H. However, when you click the hyperlinks in column A, you receive a run time error '5' (invalid procedure). This obviously is because the hyperlinks in column A are not to hidden sheets (like column H).

So, my question is,

how do I change the script below to only apply/run on the hyperlinks in column H?


Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)

Dim strAddress As String

strAddress = Application.WorksheetFunction.Substitute(Target.SubAddress, "'", vbNullString)

ThisWorkbook.Worksheets(VBA.Left$(strAddress, VBA.InStr(1, strAddress, "!") - 1)).Visible = xlSheetVisible

Application.EnableEvents = False

Target.Follow

FixThings:

Application.EnableEvents = True
End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
how do I change the script below to only apply/run on the hyperlinks in column H?
Possibly test as
VBA Code:
Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Dim strAddress As String

If Not ActiveCell.Column = 8 Then Exit Sub
Not sure how reliable that will be.
Please post code between code tags (vba button on posting toolbar) to maintain indentation and readability.
 
Upvote 0
Solution
Possibly test as
VBA Code:
Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Dim strAddress As String

If Not ActiveCell.Column = 8 Then Exit Sub
Not sure how reliable that will be.
Please post code between code tags (vba button on posting toolbar) to maintain indentation and readability.
VBA Code:
Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Dim strAddress As String 

worked. Thank you!!!
 
Upvote 0
Glad to help. Can you mark this one as solved to save other responders time? Thanks.
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,139
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top