Hyperlinks for Sheets by code

LearnMeExcel

Well-known Member
Joined
Aug 11, 2009
Messages
746
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hi all
Code:
Sub AddHyperLink()
Dim ws As Worksheet
For Each ws In Sheets
    If ws.Name <> "Main" Then
        ws.Hyperlinks.Add Anchor:=Range("a1"), Address:="", _
        SubAddress:="Main!B2", TextToDisplay:="Back To Main"
    End If
Next ws
End Sub
this just work for one sheet not for all
should i activate every sheet before add hyperlink by
ws.activate
or what ?
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
You need to qualify your anchor reference either via ws prefix or an outer With statement, e.g:

Code:
ws.Hyperlinks.Add Anchor:=ws.Range("A1"), Address:="", _
        SubAddress:="Main!B2", TextToDisplay:="Back To Main"

or (With)

Code:
With ws
    .Hyperlinks.Add Anchor:=.Range("A1"), Address:="", _
        SubAddress:="Main!B2", TextToDisplay:="Back To Main"
End With
 
Upvote 0

Forum statistics

Threads
1,224,532
Messages
6,179,388
Members
452,908
Latest member
MTDelphis

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