VBA to link to hidden sheets

newbie188

New Member
Joined
Feb 16, 2021
Messages
9
Office Version
  1. 2016
Platform
  1. Windows
Hi, complete newb. I was looking to hide sheets that are linked from a Title Sheet. I followed the code from
but I'm getting an error, as highlighted below. I assumed I would need to change something from the code in the video but can't see what. should (MySheet) actually be the name of a specific sheet? The video was excellent but I can't get the code to work.

VBA Code:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
    LinkTo = Target.SubAddress
    WhereBang = InStr(1, LinkTo, "!")
    If WhereBang > 0 Then
        MySheet = Left(LinkTo, WhereBang - 1)
        [COLOR=rgb(226, 80, 65)]Worksheets(MySheet).Visible = True[/COLOR]
        Worksheets(MySheet).Select
        MyAddr = Mid(LinkTo, WhereBang + 1)
       
        Worksheets(MySheet).Range(MyAddr).Select
    End If
 
 

End Sub
 
Last edited by a moderator:

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi & welcome to MrExcel.
How about
VBA Code:
        MySheet = Replace(Left(LinkTo, WhereBang - 1), "'", "")
 
Upvote 0
What error do you get & what is the name of the sheet?
 
Upvote 0
What error do you get & what is the name of the sheet?
I went into the workbook for the first time in a few weeks and it sort of works now?! I say 'sort of' because the individual sheets are hidden but when I click on the links for the sheets, it unhides the sheets and they remain unhidden after that. maybe that's the way it's supposed to be?
 
Upvote 0
That's the way it works, if you want the sheets to be hidden when you leave them, put this in the sheet module for each hidden sheet
VBA Code:
Private Sub Worksheet_Deactivate()
   Me.Visible = xlSheetHidden
End Sub
 
Upvote 0
This script works great if the Worksheet does not have spaces or special characters. Is there a way around this?

Thank you!
 
Upvote 0
Please start a thread of your own, showing the code that you are using. Thanks
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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