Open hyperlink with macro in all sheets of a workbook

Sub Macro4()
    Selection.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
End Sub

I have one Excel workbook with three sheets (sheet 1, sheet 2 & sheet 3), in sheet1 in B1 cell I have hyperlink which I open with the recorded macro command, however when I run the macro in sheet no. 2 then command fails with error run-time error '9'.

Please help as I want to use this command in such a way that if I have opened sheet2 or sheet 3 then still it may open the hyperlink of sheet 1.


Sub Macro4()
    Worksheets("sheet1").Range("B1").Hyperlinks(1).Follow NewWindow:=False, AddHistory:=True
End Sub

You need to tell VBA that the hyperlink is on another sheet if your referencing it from a different sheet. By adding Worksheets("Sheet1") your telling VBA to always look at Sheet1 regardless of what sheet is actually activated. The Range("B1") is simply narrowing the range in which a hyperlink can be found and deemed as the 1st hyperlink

Need Your Help

visible binding not working properly

javascript html knockout.js

I am currently working on a project where I want a button to register the number of clicks and show a message when the user clicks on the button first time. Here is what the code looks like. Pleas...

canvas update with drawImage from buffer don't apply actions with drawImage

jquery html5 canvas buffer drawimage

I use the buffering method to update a canvas, the thing is when I draw an Image in my buffer canvas and apply it to the real canvas there is no image at the real canvas. But I can apply anything e...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.