简体   繁体   中英

Excel worksheet().Activate not working within function

I am struggling with getting another tab within my document to activate within a function I am running - it works fine when I debug, but as soon as I run it, the rest of the code runs, but it just doesn't switch tabs.

Here is a snippet of some of the code

Function HyperlinkClick()

'Run some other Code...

Worksheets("Delivery Note").Activate

End Function

I am running it as a Function in a separate module as I need to have it linking from a hyperlink that is only created on each row as it is filled out ie:

=IF(C2>0,HYPERLINK("#HyperlinkClick()","Reprint"),"")

Has anyone got any ideas on why this is or another way of achieving this?

Thanks in anticipation!

Some restrictions on what you can do in a function evoked from a hyperlink apply (though not exactly as they do for UDF's), but if you want the link to take you to a different location, then return that location from your function:

Function HyperlinkClick()

    'other code here (with restrictions)

    Set HyperlinkClick = Worksheets("Delivery Note").Range("A1")

End Function

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM