+ Reply to Thread
Results 1 to 7 of 7

Scope and Lifetime confusion.

Hybrid View

Guest Scope and Lifetime confusion. 07-06-2005, 10:05 PM
Guest Re: Scope and Lifetime... 07-07-2005, 04:05 AM
Guest Re: Scope and Lifetime... 07-07-2005, 07:05 AM
Guest Re: Scope and Lifetime... 07-07-2005, 07:05 AM
Guest Re: Scope and Lifetime... 07-07-2005, 08:05 AM
Guest Re: Scope and Lifetime... 07-07-2005, 08:05 AM
Guest Re: Scope and Lifetime... 07-07-2005, 09:05 AM
  1. #1
    Harald Staff
    Guest

    Re: Scope and Lifetime confusion.

    Ok. Demo, place in the ThisWorkbook module of a new empty workbook:

    Option Explicit

    Dim BlnAuto As Boolean

    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    If BlnAuto = False Then
    On Error Resume Next
    Sh.Range("B2").Select
    End If
    End Sub

    Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, _
    ByVal Target As Range, Cancel As Boolean)
    BlnAuto = Not BlnAuto
    End Sub

    This selects B2 on sheet activation, and you disable-enable this behavior by
    doubleclicking a cell.

    HTH. Best wishes Harald

    <hanjohn@netspace.net.au> skrev i melding
    news:1120732526.721444.136740@f14g2000cwb.googlegroups.com...
    > Sorry, that's not what I need. My workbook is multisheet. Say I'm
    > working (entering test marks for example) in a column that has to be
    > scrolled to because it is so far to the right. If I then click a sheet
    > tab to view another sheet (for whatever reason) and then back to the
    > original sheet I was working on, I have to scroll again to get to the
    > column I was working on. It works that way because of the code I've
    > placed in each Worksheet_Activate event procedure i.e;
    > Range("B1").Select.
    > All I want to do is code in the ability to over-ride the effect if the
    > code in the Event Procedures so that I don't have to scroll to get back
    > to an off-screen area when returning to a sheet. I just can't figure
    > out to set it up so that the user can run a Sub procedure that results
    > in a variable that is visible to the Worksheet_Activate event procedure
    > and has a lifetime that is as long as the workbook is open. The value
    > of that variable determines whether or not B1 is selected when a sheet
    > is activated.
    >




  2. #2
    hanjohn@netspace.net.au
    Guest

    Re: Scope and Lifetime confusion.

    Thanks Harald, I'll try that out.


  3. #3
    hanjohn@netspace.net.au
    Guest

    Re: Scope and Lifetime confusion.

    Great work Harald! It works beautifully. Also, I'm impressed that I
    only have to use the This Workbook module instead of all of the
    Worksheet modules and a standard Sub procedure.
    Thanks again.
    Ken Johnson.


  4. #4
    Harald Staff
    Guest

    Re: Scope and Lifetime confusion.

    Glad to hear that Ken. Thanks for the feedback.

    Best wishes Harald

    <hanjohn@netspace.net.au> skrev i melding
    news:1120737495.854874.270880@g43g2000cwa.googlegroups.com...
    > Great work Harald! It works beautifully. Also, I'm impressed that I
    > only have to use the This Workbook module instead of all of the
    > Worksheet modules and a standard Sub procedure.
    > Thanks again.
    > Ken Johnson.
    >




+ 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