Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default run procedure when exit design mode

Hi,

I have some procedures with static variables like "blnInitDone" to prevent a
very large and time-consuming piece of code to run more than once. These
procedures are typically called when opening the workbook.
Now every time I enter and exit design mode, these variables lose their
value so the large piece of code gets run again (which isn't necessary).

Is there any way to make a procedure run automatically whenever I exit
design mode as to initialise the values correctly? Or to link a macro to the
"Exit Design Mode" button (but then I guess you have to be able to determine
whether you're already in desing mode or not, otherwise the macro also gets
run when you enter design mode...)

Thanks.
-=Wim=-

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default run procedure when exit design mode

I suppose the problem is that you have a Boolean whose value upon
initialisation is False. Hence, you cannot tell if that is the real, set
value, or the value assigned due to a Reset/End.
Why not use a say a string instead, so you can test if it has been
initialised and if not set it to the required value, maybe either "True" or
"False"

Dim TestString As String

Private Sub CommandButton1_Click()

Debug.Print StrPtr(TestString) = 0

If MsgBox("Call End ?", vbYesNo) = vbYes Then
End
Else
TestString = ""
End If

End Sub

NickHK

"Wim SKW" wrote in message
...
Hi,

I have some procedures with static variables like "blnInitDone" to prevent

a
very large and time-consuming piece of code to run more than once. These
procedures are typically called when opening the workbook.
Now every time I enter and exit design mode, these variables lose their
value so the large piece of code gets run again (which isn't necessary).

Is there any way to make a procedure run automatically whenever I exit
design mode as to initialise the values correctly? Or to link a macro to

the
"Exit Design Mode" button (but then I guess you have to be able to

determine
whether you're already in desing mode or not, otherwise the macro also

gets
run when you enter design mode...)

Thanks.
-=Wim=-



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default run procedure when exit design mode

"NickHK" wrote:

I suppose the problem is that you have a Boolean whose value upon
initialisation is False. Hence, you cannot tell if that is the real, set
value, or the value assigned due to a Reset/End.
Why not use a say a string instead, so you can test if it has been
initialised and if not set it to the required value, maybe either "True" or
"False"


Mmm. Not really, Nick.
When I enter and exit design mode this string would also loose its value! I
could store the value an a worksheet cell, but then I would have to read this
value in EVERY event procedure, which is not practical. This is the reason
why I've used a variable in the first place.
Basically the code that is run upon opening the workbook should also be run
when exiting design mode, preferably in an automatic way.
Any suggestions?
-=Wim=-
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default run procedure when exit design mode

Maybe you could just run your initialization routine manually.

But it may be worth your effort to check to see if the variables are initialized
before you use them.

Add another variable in a general module:

Public VarsAreInitialized As Boolean

Then before you rely on them being ok (in each sub that uses them):

If varsareinitialized = false then
call initializevars
end if

Have one procedure that does the work:

Sub InitializeVars()
'initialize all your variables
'plus this one:
VarsAreInitialized = true
end sub



Wim SKW wrote:

Hi,

I have some procedures with static variables like "blnInitDone" to prevent a
very large and time-consuming piece of code to run more than once. These
procedures are typically called when opening the workbook.
Now every time I enter and exit design mode, these variables lose their
value so the large piece of code gets run again (which isn't necessary).

Is there any way to make a procedure run automatically whenever I exit
design mode as to initialise the values correctly? Or to link a macro to the
"Exit Design Mode" button (but then I guess you have to be able to determine
whether you're already in desing mode or not, otherwise the macro also gets
run when you enter design mode...)

Thanks.
-=Wim=-


--

Dave Peterson
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
run procedure when exit design mode Wim SKW Excel Discussion (Misc queries) 1 July 11th 07 09:24 AM
I can't exit from Design mode anymore Ray Excel Discussion (Misc queries) 0 April 20th 06 02:31 PM
Can't Exit Design Mode MT DOJ Help Desk[_2_] Excel Programming 4 December 6th 03 06:11 AM
Can't Exit Design Mode because Control can not be Created MT DOJ Help Desk Excel Programming 0 November 21st 03 05:37 AM
Enter Excel Design Mode and Exit Design Mode Bill Lunney Excel Programming 0 August 4th 03 07:48 AM


All times are GMT +1. The time now is 04:43 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"