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
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
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
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
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