Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Scope and Lifetime confusion.

I am using Excel (98 for Macintosh)as a teachers' markbook with student
names in column A,test results in the other columns and different
classes on different sheets.It is set up so that student's marks for
the first test (in column B) are visible after the sheet is activated
by clicking the sheet tab (each sheet module has "Range("B1").Select"
in the Worksheet_Activate Event Procedure).
I want the option of overriding this behaviour so that clicking a sheet
tab takes you back to the part of the sheet on which you were
previously working i.e; normal between-sheet behaviour.
I am thinking along the lines of a standard Sub Procedure which when
run sets a Boolean variable named StayPut to True. I want StayPut to be
visible to all the Worksheet_Activate Subs and its lifetime to be the
time that the Workbook is open. I've included "If StayPut then (new
line) Exit Sub (new line) End if" at the start of each sheet's
Worksheet_Activate Event Procedure. Nothing I do works.
Is anybody able to help me? Scope and lifetime have me totally confused!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 292
Default Scope and Lifetime confusion.

Hi

I'm not really sure what you ask here, but John Walkenbach has code that
syncronize sheets at
http://j-walk.com/ss/excel/tips/tip75.htm

HTH. Best wishes Harald

skrev i melding
oups.com...
I am using Excel (98 for Macintosh)as a teachers' markbook with student
names in column A,test results in the other columns and different
classes on different sheets.It is set up so that student's marks for
the first test (in column B) are visible after the sheet is activated
by clicking the sheet tab (each sheet module has "Range("B1").Select"
in the Worksheet_Activate Event Procedure).
I want the option of overriding this behaviour so that clicking a sheet
tab takes you back to the part of the sheet on which you were
previously working i.e; normal between-sheet behaviour.
I am thinking along the lines of a standard Sub Procedure which when
run sets a Boolean variable named StayPut to True. I want StayPut to be
visible to all the Worksheet_Activate Subs and its lifetime to be the
time that the Workbook is open. I've included "If StayPut then (new
line) Exit Sub (new line) End if" at the start of each sheet's
Worksheet_Activate Event Procedure. Nothing I do works.
Is anybody able to help me? Scope and lifetime have me totally confused!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Scope and Lifetime confusion.

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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 292
Default 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

skrev i melding
oups.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.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Scope and Lifetime confusion.

Thanks Harald, I'll try that out.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default 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.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 292
Default Scope and Lifetime confusion.

Glad to hear that Ken. Thanks for the feedback.

Best wishes Harald

skrev i melding
oups.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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lifetime of VBA variables Alan Beban[_2_] Excel Programming 4 April 2nd 05 06:36 PM
scope/ lifetime of variable jeffP Excel Programming 5 September 19th 04 05:25 AM
scope/ lifetime of variable Norman Jones Excel Programming 0 September 18th 04 12:55 AM
!!!! A chance of a lifetime !!! Good Excel Programming 0 June 3rd 04 06:14 AM
!!!! A chance of a lifetime !!! Good Excel Programming 0 June 3rd 04 06:14 AM


All times are GMT +1. The time now is 01:50 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"