+ Reply to Thread
Results 1 to 7 of 7

Scrollbar Name

Hybrid View

  1. #1
    Registered User
    Join Date
    10-08-2012
    Location
    Cedar Falls, Iowa
    MS-Off Ver
    Excel 2007
    Posts
    50

    Scrollbar Name

    I need VBA to return the name of a Scrollbar after it is clicked (i.e. - in the scrollbar change event). How do I do that?

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,896

    Re: Scrollbar Name

    The scrollbar change event is specific to a particular scrollbar, so you already have to know its name to write the event handler.

    Can you give the bigger picture of what you're trying to do? Where and how do you need to use the name? That is, return it to where?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    10-08-2012
    Location
    Cedar Falls, Iowa
    MS-Off Ver
    Excel 2007
    Posts
    50

    Re: Scrollbar Name

    Yes - after the scrollbar is changed, I would like VBA to pass the name of the Scrollbar into a different routine. I have a worksheet with several Slider Bars (aka Scrollbars) on it and I would like to assign the same Macro to each one, with the Name unique for each one.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,896

    Re: Scrollbar Name

    This is a little complicated, if I understand correctly what you want to do. The strategy is to write a class for the scrollbars so a single Sub can handle a Change event no matter which scrollbar caused it. I have attached an example of how to do this with checkboxes that was adapted from a solution posted by member Andy Pope some time back.

    But before I go into that explanation you still need to give more information about your overall problem. "I would like to assign the same Macro to each one, with the Name unique for each one." I can't make sense out of the second half of this. Please describe what you want to happen when the scrollbars are changed.

  5. #5
    Registered User
    Join Date
    10-08-2012
    Location
    Cedar Falls, Iowa
    MS-Off Ver
    Excel 2007
    Posts
    50
    Quote Originally Posted by 6StringJazzer View Post
    This is a little complicated, if I understand correctly what you want to do. The strategy is to write a class for the scrollbars so a single Sub can handle a Change event no matter which scrollbar caused it. I have attached an example of how to do this with checkboxes that was adapted from a solution posted by member Andy Pope some time back.

    But before I go into that explanation you still need to give more information about your overall problem. "I would like to assign the same Macro to each one, with the Name unique for each one." I can't make sense out of the second half of this. Please describe what you want to happen when the scrollbars are changed.
    So the Scrollbars represent years, from 2018 out to 2030. The user selects which year a program will begin. I am hoping I can rename each Scrollbar to match the Program Name, because I need to reference that in a separate routine.

    Basically, I need to set the name off the scrollbar to a variable within the Scrollbar Change Event and then pass that to a different routine.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,896

    Re: Scrollbar Name

    In the file I attached, in Class CChk, the Sub MyChk_Click will handle the Click event from any checkbox. It then calls a Sub SingleCheck in whatever module owns the checkbox and passes in the checkbox name. If you take the file I attached and change all occurrences of CheckBox to ScrollBar it may work, I haven't tried it to confirm.

    Note that Sub UserForm1.UserForm_Initialize sets up the collection of checkboxes to begin with, necessary for this scheme to work. It's easy in a userform because you can use the Initialize method. If your controls are in a worksheet, we would have to move this to the ThisWorkbook.Workbook_Open sub.

    If you need additional help, attach your file.

  7. #7
    Registered User
    Join Date
    10-08-2012
    Location
    Cedar Falls, Iowa
    MS-Off Ver
    Excel 2007
    Posts
    50
    Quote Originally Posted by 6StringJazzer View Post
    In the file I attached, in Class CChk, the Sub MyChk_Click will handle the Click event from any checkbox. It then calls a Sub SingleCheck in whatever module owns the checkbox and passes in the checkbox name. If you take the file I attached and change all occurrences of CheckBox to ScrollBar it may work, I haven't tried it to confirm.

    Note that Sub UserForm1.UserForm_Initialize sets up the collection of checkboxes to begin with, necessary for this scheme to work. It's easy in a userform because you can use the Initialize method. If your controls are in a worksheet, we would have to move this to the ThisWorkbook.Workbook_Open sub.

    If you need additional help, attach your file.
    Great! I will give that a try aveand get back to you...thanks so much for the help

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Scrollbar help!
    By xia0lis in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-29-2013, 12:05 PM
  2. Change ScrollBar Max value when a second ScrollBar vale is changed?
    By Jon Henry in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-11-2013, 06:47 PM
  3. ScrollBar
    By Kenji in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-24-2010, 02:42 PM
  4. Scrollbar
    By Iegion in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-10-2009, 03:47 AM
  5. Scrollbar
    By Scottmk in forum Excel General
    Replies: 1
    Last Post: 03-15-2007, 09:53 PM
  6. [SOLVED] When a scrollbar is not a scrollbar
    By Flash in the Pan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-27-2006, 10:40 PM
  7. [SOLVED] Scrollbar
    By dstiefe in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-12-2005, 04:05 PM
  8. [SOLVED] scrollbar reslut makes another scrollbar to show
    By Patrik in forum Excel General
    Replies: 0
    Last Post: 04-18-2005, 11:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1