View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default non basic code in call stack

If I correctly understand, you have the same name procedure defs in
both files. To avoid issues like this I declare each
mdule/userform/class that reuses same defs as 'Private', meaning the
code page starts with...

Option Explicit
Option Private Module

Const sModule$ = "ModuleNameGoesHere"

...so when 2 or more projects are open they don't run each other's same
name code defs. A typical example is the proc that I use to display
help in every project is named "ShowHelp" if using CHM, "ShowHelpHE" if
using EXE. Declaring the containing module as 'private' prevents other
project code from running either of these defs.

The purpose of the sModule constant is to provide an identifier for app
logs. I also use similar in defs so code knows which def is the
'caller'...

Sub MySub()
Const sSource$ = "MySub"
'...code follows
End Sub 'MySub

OR

Function ReadTextFile$(Filename$)
Const sSource$ = "ReadTextFile()"
'...code follows
End Function 'ReadTextFile()

...where the convention is to include parenthesis for functions in order
to distinguish these from subs when reading app logs.

A typical use for def IDs is how I manage Excel settings while code is
running, so defs don't trigger settings inadvertedly...

Sub EnableFastCode(Caller$, Optional SetFast As Boolean = True)
'The following will make sure only the Caller has control,
'and allows any Caller to take control when not in use.
If AppMode.CallerID < Caller Then _
If AppMode.CallerID < "" Then Exit Sub

With Application
If SetFast Then
AppMode.Display = .ScreenUpdating
.ScreenUpdating = False
AppMode.CalcMode = .Calculation
.Calculation = xlCalculationManual
AppMode.Events = .EnableEvents
.EnableEvents = False
AppMode.CallerID = Caller
Else
.ScreenUpdating = AppMode.Display
.Calculation = AppMode.CalcMode
.EnableEvents = AppMode.Events
AppMode.CallerID = ""
End If
End With
End Sub 'EnableFastCode

...which requires the following 'Type' declaration to work correctly.

Type udtAppModes
Events As Boolean
CalcMode As XlCalculation
Display As Boolean
CallerID As String
End Type
Public AppMode As udtAppModes

To use the procedure I just call it from any def and pass the args as
needed...

Sub MySub()
Const sSource$ = "MySub"
EnableFastCode sSource '//turn it on
'...code follows
EnableFastCode sSource, False ''//turn it off
End Sub 'MySub

...and as long as this def has control of those settings they won't get
triggered by other code in the call stack that also uses
'EnableFastCode'!

HTH

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion