VBA code run time error

Jody Gelbach 1 Reputation point
2022-09-28T13:49:37.19+00:00

I have the following code in one of my sheets to have a hyperlink back to the home page, then hide that current sheet. I also have other hyperlinks in that sheet that will take you to a saved file on our network. When i select any other hyperlink other than the one that executes the back to home page, it opens my file, yet gives me a run time error.

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Sheet1.Select
Sheet13.Visible = xlSheetHidden
End Sub

Excel Management
Excel Management
Excel: A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.Management: The act or process of organizing, handling, directing or controlling something.
1,657 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 112.9K Reputation points
    2022-09-28T17:19:29.497+00:00

    I think that you can analyze some properties of Target and skip the code. In simple cases, check the text of the link. For example, if your link is "Home", then:

    Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)  
       If Target.TextToDisplay = "Home" Then   
          Sheet1.Select  
          Sheet13.Visible = xlSheetHidden  
       End If  
    End Sub  
    
    0 comments No comments