View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
RJQMAN[_2_] RJQMAN[_2_] is offline
external usenet poster
 
Posts: 54
Default Should I activate workbook before activating sheet when button is selected?

On Sep 13, 1:14*pm, GS wrote:
To add to Mick's suggestion, it would just be good programming practice
to set object refs in code to each open workbook your code acts on.
Usually, you would then not need to activate any workbook or worksheet
because your code knows which is which when you use object refs!

--
Garry

Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


I do not know how to set those object refs. My code always is
intended to act only on the workbook that is open - there is no cross
referencing to any other workbooks. However, it is common for a user
to make a 2nd copy of the program and have it active at the samne time
if they are scoring two different events (that are not simultaneous -
always the events follow one another). They receive the program from
me, they may and probably do rename it, and then use it.

As tp setting the object ref, could you give me an example? I am a
self-taught programmer. I have worked on this program for 3 years,
and it is finally running well and meeting all the needs of the
users. I just do not want a nuisance crash.

As to posting my code, there are over 100 command buttons in the
program - all on the pages that the user can use to set the program up
for their specific contest. It is hard to find an exact example that
will explain the problem, but I am including a typical macro below, if
that is of help. I think your specific suggestion, Garry, is what I
need to do. I just do not understand how to do it.

Here is my code for run of the command buttons - it is fairly
typical. Some of the subs are much more complex, of course, but they
all open with something similar - either a statement that calls a
subroutine that unprotects a sheet, or something like the following;

Sub FMBC92_A91G_OK_PlaceScore()

activesheet("Scores");range("E2").value=5

End Sub

here is am actual sub;

Sub FMBC02_W03G_SP_Deactivate()
'
' ================== UNPROTECT SHEET ====================
'
Call FMBC02_Activate_and_Unprotect_Contest_Data
Application.ScreenUpdating = False
'
' ============ DEACTIVATE SPECIAL CLASSES ===============
'
ActiveSheet.Rows("115:129").Hidden = True
ActiveSheet.Range("BP110:BQ112").VerticalAlignment = xlBottom
ActiveSheet.Range("X110:BQ112").Interior.ColorInde x = 8

Call FMBC02_W03H_RO_Deactivate
Call FMBC02_W03I_RS_Deactivate
Call FMBC02_W03I_SH_Deactivate
Call FMBC02_W03V_CO_Deactivate
'
' ========== POSITION CURSOR AND PROTECT SHEET ==========
'
ActiveSheet.Range("AU100").Select
ActiveSheet.Protect
'
End Sub

I hope this is the information you need. But I think what I need is
to know better what would be good programming practice here.

Thank you for responding. It is very much appreciated.