+ Reply to Thread
Results 1 to 5 of 5

Worksheet Navigation

Hybrid View

Guest Worksheet Navigation 07-12-2005, 03:05 PM
Guest RE: Worksheet Navigation 07-12-2005, 04:05 PM
Guest RE: Worksheet Navigation 07-12-2005, 06:05 PM
Guest RE: Worksheet Navigation 07-13-2005, 09:05 AM
Guest RE: Worksheet Navigation 07-18-2005, 01:05 PM
  1. #1
    subseaguy
    Guest

    Worksheet Navigation

    I have a workbook with 12 worksheets. I want to be able to hyperlink from
    one worksheet to another, then use a command button to return to the previous
    button (i.e. fire HL on WS1 which goes to specific location on WS2, then fire
    a macro via command button to return to original location in WS1). Not sure
    how to do this. Can you pass variables to/from PSubs in the same module?

  2. #2
    K Dales
    Guest

    RE: Worksheet Navigation

    First, in ThisWorkbook's code module, put in this event procedure:

    Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target
    As Hyperlink)
    Set LinkBack = Target.Range
    End Sub

    LinkBack is a Global variable defined in a separate code module:
    Public LinkBack as Range

    Finally, the code for the buttons would be like this:
    Sub Button1_Click()
    LinkBack.Parent.Activate ' to activate the source sheet
    LinkBack.Activate ' to activate the source range
    End Sub

    "subseaguy" wrote:

    > I have a workbook with 12 worksheets. I want to be able to hyperlink from
    > one worksheet to another, then use a command button to return to the previous
    > button (i.e. fire HL on WS1 which goes to specific location on WS2, then fire
    > a macro via command button to return to original location in WS1). Not sure
    > how to do this. Can you pass variables to/from PSubs in the same module?


  3. #3
    subseaguy
    Guest

    RE: Worksheet Navigation

    OK.. let me make sure I understand...
    On WS1 (where I am initiating HL) tab, "View Code" and insert

    Public LinkBack as Range
    Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target
    As Hyperlink)
    Set LinkBack = Target.Range
    End Sub

    Then in workbook, insert code for button;
    Sub Button1_Click()
    LinkBack.Parent.Activate ' to activate the source sheet
    LinkBack.Activate ' to activate the source range
    End Sub

    Have I understood your suggestion?

    Thanks,
    SubseaGuy

    "K Dales" wrote:

    > First, in ThisWorkbook's code module, put in this event procedure:
    >
    > Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target
    > As Hyperlink)
    > Set LinkBack = Target.Range
    > End Sub
    >
    > LinkBack is a Global variable defined in a separate code module:
    > Public LinkBack as Range
    >
    > Finally, the code for the buttons would be like this:
    > Sub Button1_Click()
    > LinkBack.Parent.Activate ' to activate the source sheet
    > LinkBack.Activate ' to activate the source range
    > End Sub
    >
    > "subseaguy" wrote:
    >
    > > I have a workbook with 12 worksheets. I want to be able to hyperlink from
    > > one worksheet to another, then use a command button to return to the previous
    > > button (i.e. fire HL on WS1 which goes to specific location on WS2, then fire
    > > a macro via command button to return to original location in WS1). Not sure
    > > how to do this. Can you pass variables to/from PSubs in the same module?


  4. #4
    K Dales
    Guest

    RE: Worksheet Navigation

    Not quite: The main requirement is that the Workbook_SheetFollowHyperlink
    Sub must go in ThisWorkbook's code module. That is, when you are in the VB
    editor, make sure you can see the Project Explorer and double-click on the
    line that says "ThisWorkbook." You can make sure you are typing it in the
    right place by checking the title bar of the VB editor: it should say
    something like "Microsoft Visual Basic - Book1 - [ThisWorkbook (Code)]" The
    reason the sub must be in here is that it is an event procedure that runs
    automatically whenever the specified event takes place - in this case
    whenever a hyperlink is followed. But that operates for the workbook as a
    whole and so it has to be in the code module for the workbook for it to be
    recognized and to function.

    For the Button_Click code, the easiest thing to do is create the button from
    the forms toolbar and then when the "Assign Macro" dialog comes up, specify
    "New..." It will create a new module and you can type the code in there. But
    you can also type that code in any module (ThisWorkbook, Sheet1, ...) and
    manually assign the macro to your button as long as you make it a Public Sub.

    Same thing with the global variable LinkBack - it can go in any module as
    long as it is declared Public.

    --
    - K Dales


    "subseaguy" wrote:

    > OK.. let me make sure I understand...
    > On WS1 (where I am initiating HL) tab, "View Code" and insert
    >
    > Public LinkBack as Range
    > Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target
    > As Hyperlink)
    > Set LinkBack = Target.Range
    > End Sub
    >
    > Then in workbook, insert code for button;
    > Sub Button1_Click()
    > LinkBack.Parent.Activate ' to activate the source sheet
    > LinkBack.Activate ' to activate the source range
    > End Sub
    >
    > Have I understood your suggestion?
    >
    > Thanks,
    > SubseaGuy
    >
    > "K Dales" wrote:
    >
    > > First, in ThisWorkbook's code module, put in this event procedure:
    > >
    > > Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target
    > > As Hyperlink)
    > > Set LinkBack = Target.Range
    > > End Sub
    > >
    > > LinkBack is a Global variable defined in a separate code module:
    > > Public LinkBack as Range
    > >
    > > Finally, the code for the buttons would be like this:
    > > Sub Button1_Click()
    > > LinkBack.Parent.Activate ' to activate the source sheet
    > > LinkBack.Activate ' to activate the source range
    > > End Sub
    > >
    > > "subseaguy" wrote:
    > >
    > > > I have a workbook with 12 worksheets. I want to be able to hyperlink from
    > > > one worksheet to another, then use a command button to return to the previous
    > > > button (i.e. fire HL on WS1 which goes to specific location on WS2, then fire
    > > > a macro via command button to return to original location in WS1). Not sure
    > > > how to do this. Can you pass variables to/from PSubs in the same module?


  5. #5
    subseaguy
    Guest

    RE: Worksheet Navigation

    KD,

    I did what you said and I get an "Object Required" error (424). Any thoghts?

    "subseaguy" wrote:

    > I have a workbook with 12 worksheets. I want to be able to hyperlink from
    > one worksheet to another, then use a command button to return to the previous
    > button (i.e. fire HL on WS1 which goes to specific location on WS2, then fire
    > a macro via command button to return to original location in WS1). Not sure
    > how to do this. Can you pass variables to/from PSubs in the same module?


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1