ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Multi-page and Scroll bars (https://www.excelbanter.com/excel-programming/354408-multi-page-scroll-bars.html)

VBA Fun

Multi-page and Scroll bars
 
I have a multipage object on a userform. I programatically add a number of
controls. Depending on the number of conrols I add, I want to have the
scrollbars function to allow the user to see all of the controls.

I can make the vertical scroll bar visible and keep it visible...but
regardless of what I do, the scroll bars don't function.

Any advice?
--
VBA Fun

K Dales[_2_]

Multi-page and Scroll bars
 
What code have you attached to the scrollbar _Change event? Forgive me if I
am telling you something you already know here, but in case not: When you add
a scroll bar to a user form it does not automatically give you the ability to
scroll the page. It is just an empty control like any other until you tell
it how to respond. So you would need to have code that moves your controls
on the page in synch with the scroll bar. As a quick example you can try
something like this and see what it can do (you need a button on the form,
any location to start with):

Private Sub ScrollBar1_Change()

CommandButton1.Top = (Me.Height - CommandButton1.Height) * _
(ScrollBar1.Value - ScrollBar1.Min) / (ScrollBar1.Max - ScrollBar1.Min)

End Sub

You could potentially iterate through all controls with a For Each
statement. You would need to modify the above so it tracks the control's
start position and does everything relative to that (my simple code always
brings it to the top of the form)

--
- K Dales


"VBA Fun" wrote:

I have a multipage object on a userform. I programatically add a number of
controls. Depending on the number of conrols I add, I want to have the
scrollbars function to allow the user to see all of the controls.

I can make the vertical scroll bar visible and keep it visible...but
regardless of what I do, the scroll bars don't function.

Any advice?
--
VBA Fun


VBA Fun

Multi-page and Scroll bars
 
Thank you for the feedback. I am surprised by the response. I figured that
the scroll bar is a part of the control and not a control itself..a as the
scrollbar was not added by me, but made visible as a property of the page
itself. I don't know if this sheds any additional lighton the issue. I will
look to write code to 'scroll' the contents of the page.

Thanks for your quick reply.
--
VBA Fun


"K Dales" wrote:

What code have you attached to the scrollbar _Change event? Forgive me if I
am telling you something you already know here, but in case not: When you add
a scroll bar to a user form it does not automatically give you the ability to
scroll the page. It is just an empty control like any other until you tell
it how to respond. So you would need to have code that moves your controls
on the page in synch with the scroll bar. As a quick example you can try
something like this and see what it can do (you need a button on the form,
any location to start with):

Private Sub ScrollBar1_Change()

CommandButton1.Top = (Me.Height - CommandButton1.Height) * _
(ScrollBar1.Value - ScrollBar1.Min) / (ScrollBar1.Max - ScrollBar1.Min)

End Sub

You could potentially iterate through all controls with a For Each
statement. You would need to modify the above so it tracks the control's
start position and does everything relative to that (my simple code always
brings it to the top of the form)

--
- K Dales


"VBA Fun" wrote:

I have a multipage object on a userform. I programatically add a number of
controls. Depending on the number of conrols I add, I want to have the
scrollbars function to allow the user to see all of the controls.

I can make the vertical scroll bar visible and keep it visible...but
regardless of what I do, the scroll bars don't function.

Any advice?
--
VBA Fun


Tom Ogilvy

Multi-page and Scroll bars
 
Yes, there is a built in scrollbar for the userform (and the multipage
control). K Dales is speaking of the scrollbar control which is different.

Size your multipage (assume multipage1) so you can put all your controls on
the the multipage (on the first page/tab, page index zero). Then select the
bottom the multipage and make the multipage about half its height. (so half
the controls are not visible). Now put this code in the Userform Module:

Private Sub UserForm_Initialize()
MultiPage1.Pages(0).ScrollBars = _
fmScrollBarsVertical
MultiPage1.Pages(0).KeepScrollBarsVisible = _
fmScrollBarsVertical
MultiPage1.Pages(0).ScrollHeight = _
2 * MultiPage1.Height
MultiPage1.Pages(0).ScrollTop = _
MultiPage1.Height / 2
End Sub

Now display the userform and the scrollbar should work.

--
Regards,
Tom Ogilvy


"VBA Fun" .(donotspam) wrote in message
...
Thank you for the feedback. I am surprised by the response. I figured

that
the scroll bar is a part of the control and not a control itself..a as the
scrollbar was not added by me, but made visible as a property of the page
itself. I don't know if this sheds any additional lighton the issue. I

will
look to write code to 'scroll' the contents of the page.

Thanks for your quick reply.
--
VBA Fun


"K Dales" wrote:

What code have you attached to the scrollbar _Change event? Forgive me

if I
am telling you something you already know here, but in case not: When

you add
a scroll bar to a user form it does not automatically give you the

ability to
scroll the page. It is just an empty control like any other until you

tell
it how to respond. So you would need to have code that moves your

controls
on the page in synch with the scroll bar. As a quick example you can

try
something like this and see what it can do (you need a button on the

form,
any location to start with):

Private Sub ScrollBar1_Change()

CommandButton1.Top = (Me.Height - CommandButton1.Height) * _
(ScrollBar1.Value - ScrollBar1.Min) / (ScrollBar1.Max -

ScrollBar1.Min)

End Sub

You could potentially iterate through all controls with a For Each
statement. You would need to modify the above so it tracks the

control's
start position and does everything relative to that (my simple code

always
brings it to the top of the form)

--
- K Dales


"VBA Fun" wrote:

I have a multipage object on a userform. I programatically add a

number of
controls. Depending on the number of conrols I add, I want to have

the
scrollbars function to allow the user to see all of the controls.

I can make the vertical scroll bar visible and keep it visible...but
regardless of what I do, the scroll bars don't function.

Any advice?
--
VBA Fun





All times are GMT +1. The time now is 08:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com