LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Public variable is reset after addin macro completes - thread/focus pblm?

Hello,

I have an addin macro (Excel 2K on Win XP) that creates a custo
worksheet and a custom toolbar for the sheet. The toolbar should onl
be active when the sheet is visible, and the user may add multipl
custom sheets as well as others.

The problem is that the public variable (SababarIsActive) I am using t
track if the toolbar is active is reset to false once the macr
completes.


The public variable "SababarIsActive" is added to a standard module an
the following event handler is added to the "thisWorkbook" module b
the addin macro:


Code
-------------------


------------------- Saba_GlobalVarDefs module ---------------
Option Explicit

Public SababarIsActive As Boolean, SababarExists As Boolean 'SabaFunctiona

------------------- thisWorkbook module -----------------------
Private Sub Workbook_SheetActivate(ByVal Sh As Object) 'SabaFunctionb

Set_Security_Level_Proc_Run

MsgBox (\"Hello from the Workbook_SheetActivate procedure...\")
DisplayVal \"SababarIsActive 1\", SababarIsActive
If Range(\"A1\").Value = \"Space Air Balance Analysis\" Then
MsgBox (\"Range-A1.Value = Space Air Balance Analysis...\")
If Application.CommandBars(\"Sababar\").Enabled = False Or _
Not SababarIsActive Then
MsgBox (\" logic for: Not SababarIsActive ... togle toolbars\")
Toggle_CommandBars
SababarIsActive = True
End If

Set_Security_Level_User
DisplayVal \"SababarIsActive 2\", SababarIsActive
Exit Sub
End If

' deactivate custom controls
If SababarIsActive Then
Toggle_CommandBars
SababarIsActive = False
End If

DisplayVal \"SababarIsActive 3\", SababarIsActive
Set_Security_Level_Off

End Sub 'SabaFunctionc



-------------------


In the last lines of the macro, I'm using

Code
-------------------


Worksheets(2).Activate
Worksheets(1).Activate


-------------------

the "Workbook_SheetActivate" code is triggered correctly and message
are in sequence:

Worksheets(2).Activate:
1) Hello from the Workbook_SheetActivate procedure...
2) SababarIsActive 1 = false
3) SababarIsActive 3 = false

Worksheets(1).Activate:
1) Hello from the Workbook_SheetActivate procedure...
2) SababarIsActive 1 = false
3) "Range-A1.Value = Space Air Balance Analysis...
4) logic for: Not SababarIsActive ... togle toolbars
5) *SababarIsActive 1 = true*

However, once the macro completes, and the "Workbook_SheetActivate
code is triggered by manually clicking on a different sheet
*"SababarIsActive " is False!* And of course it now retains the valu
each time it is flipped, unfortunatly it is logically incorrec
(inverted).


I think the problem is that the addin macro is in a workbook differen
from the event handler and this is causing the problem....

Is this a threading problem or some kind of focus/visibility issue?

Does anybody know how to get this so that "SababarIsActive " wil
retain the correct value?

thank you,
HSC

I had posted similar to this in another forum but had no resolution
please excuse the apparent repetition..

--
Message posted from http://www.ExcelForum.com

 
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
Set Public Variable on Open jlclyde Excel Discussion (Misc queries) 4 September 11th 09 07:03 PM
Public variable Jack New Users to Excel 4 March 18th 06 09:35 PM
Use Checkbox Value or Public Variable? Stratuser Excel Programming 2 February 12th 04 02:33 PM
Scope of Public Variable Dkline[_2_] Excel Programming 9 October 22nd 03 04:53 PM
public variable marwan hefnawy Excel Programming 1 September 5th 03 08:54 AM


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