Disable events in userform

Is there a way to disable Userform events within Userform code? I am trying to dynamically set scrollbar.max without triggering the Scrollbar_Change event procedure.
[165 byte] By [Joe_D] at [2007-12-23]
# 1

Hi Joe

Have you tried the Application.EnableEvents property?

JFS

JFS at 2007-8-30 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 2
My research has shown that Application.EnableEvents does not work for UserForm events because UserForms are Office Library objects and not Excel Objects. There is no built in method to Disable UserForm events.
Joe_D at 2007-8-30 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 3

Hello Joe,

I was a bit curious and tried the following:

Private Sub CommandButton1_Click()
MsgBox ("Command Click")
UserForm1.ScrollBar1.Width = 20
UserForm1.ScrollBar1.Max = 100
End Sub

Private Sub ScrollBar1_Change()
MsgBox ("In Scroll Bar Change")
End Sub

Private Sub UserForm_Initialize()
MsgBox ("In Initialise")
UserForm1.ScrollBar1.Max = 15
End Sub

The only time the ScrollBar_Change event is triggered is if I clicked on the scroll bar, or the up/down arrows of the scroll bar. The command button routine changes the width and max value and the scroll bar change was not triggered.

Chas

ChasAA at 2007-8-30 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 4

This is strange because I have just tried the same technique within my code and set breakpoints to track code incrementally and I find that dynamically setting the scrollbar.max triggers the scrollbar_change event within my form. Which version of Excel are you using? I am using Excel 2003. (Incidentally, setting the scrollbar.max within the Form_Initialize procedure is also triggering the Scrollbar_change as would be consistent with dynamically changing the scrollbar.max.)

Joe D

Joe_D at 2007-8-30 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 5

Hello Joe,

I am using Excel 2003. I tried it again today and it is still working.

In Tools - References

There are the usual 4

Visual Basic for Applications

Microsoft Excel 11.0 Objectr Library

OLE Automation

Microsoft Office 11.0 Object Library.

There is one other:

Microsoft Forms 2.0 Object Library

Try referencing these and see if it helps

Chas

ChasAA at 2007-8-30 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 6

All are checked

Joe D

Joe_D at 2007-8-30 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 7

Can you try the macro on another PC.

Sorry this is not a very good answer, or can you send me your sheet and I'll try it on my PC.

My email is charleschand@aol.com

Chas

ChasAA at 2007-8-30 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...
# 8

Neither option is practical. The code is several hundred lines, but I checked again by using breakpoints around the scrollbar.max line (immediately before, on, and immediately after) as well as in the scrollbar_change and scrollbar_scroll procedures. When the scrollbar.max line is executed, it is triggering the scrollbar_change event procedure within the form (after all, I believe it is a change to the scrollbar). When I place a scrollbar in a worksheet, I am able to avoid the scrollbar_change event by placing Application.EnableEvents=False before the scrollbar.max line.

Joe D

Joe_D at 2007-8-30 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...