+ Reply to Thread
Results 1 to 14 of 14

How Do I make a Userform Resizable or allow it to scroll

Hybrid View

Invicta084 How Do I make a Userform... 01-24-2014, 09:57 AM
Sean Thomas Re: How Do I make a Userform... 01-24-2014, 10:30 AM
Invicta084 Re: How Do I make a Userform... 01-24-2014, 10:42 AM
Izandol Re: How Do I make a Userform... 01-24-2014, 10:44 AM
Invicta084 Re: How Do I make a Userform... 01-24-2014, 10:58 AM
Izandol Re: How Do I make a Userform... 01-24-2014, 11:00 AM
Invicta084 Re: How Do I make a Userform... 01-24-2014, 11:14 AM
Invicta084 Re: How Do I make a Userform... 01-24-2014, 11:15 AM
Izandol Re: How Do I make a Userform... 01-24-2014, 11:24 AM
Invicta084 Re: How Do I make a Userform... 01-24-2014, 12:21 PM
Izandol Re: How Do I make a Userform... 01-24-2014, 12:28 PM
Andy Pope Re: How Do I make a Userform... 01-24-2014, 12:42 PM
Invicta084 Re: How Do I make a Userform... 01-24-2014, 01:07 PM
Andy Pope Re: How Do I make a Userform... 01-25-2014, 06:57 AM
  1. #1
    Registered User
    Join Date
    01-23-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    81

    How Do I make a Userform Resizable or allow it to scroll

    Hi, I have a userform I created and I'm relatively new to VBA coding, I made the sheet on my computer and it fits but other co-workers have different resolutions and cannot see all the controls on the form. What code and/or how can I make it able to be resized or allow them to scroll down to see the whole form. My resolution is 1680x1050 ill assume worst case is they have it set to 800x600. The sheet height is 595.5.

    Thanks

  2. #2
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: How Do I make a Userform Resizable or allow it to scroll

    hi, see Andy Popes site

    http://www.andypope.info/vba/Anchor.htm
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

  3. #3
    Registered User
    Join Date
    01-23-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    81

    Re: How Do I make a Userform Resizable or allow it to scroll

    Hi Sean that does help, my next question is:

    How do I do this "in the userform itself you need to declare a private class object and set the Parent reference to the userform"

    Thanks

  4. #4
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: How Do I make a Userform Resizable or allow it to scroll

    As the example code says:
       Set m_clsAnchors = New CAnchors
        
        Set m_clsAnchors.Parent = Me
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  5. #5
    Registered User
    Join Date
    01-23-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    81

    Re: How Do I make a Userform Resizable or allow it to scroll

    I see the lines of code but What I don't understand is how I make it reference me userform. If that could be explained a bit more then just pasting the lines it would be helpful.

    Thanks

  6. #6
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: How Do I make a Userform Resizable or allow it to scroll

    Those are the first two lines of the Userform_Initialize procedure which must go into your userform. This will run when the form is loaded, create an instance of the CAnchors class and assign your userform as its Parent property. (Me is a reference to the object which is running the code)

  7. #7
    Registered User
    Join Date
    01-23-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    81

    Re: How Do I make a Userform Resizable or allow it to scroll

    Eneded up posting the same post twice.
    Last edited by Invicta084; 01-24-2014 at 11:19 AM. Reason: posted twice

  8. #8
    Registered User
    Join Date
    01-23-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    81

    Re: How Do I make a Userform Resizable or allow it to scroll

    Izandol sorry for being so ignorant with this but when I put the code into my initialize script it stops at those two lines? I posted the code below, sorry I'm a complete noob at this (This is my first use of VBA coding)

    Private Sub UserForm_Initialize()
    
    Set m_clsAnchors = New CAnchors
        
        Set m_clsAnchors.Parent = Me
        
        ' restrict minimum size of userform
        m_clsAnchors.MinimumWidth = 45
        m_clsAnchors.MinimumHeight = 250
        
        With m_clsAnchors
            .Anchor("Textbox1").AnchorStyle = enumAnchorStyleLeft Or enumAnchorStyleRight
            .Anchor("cmdBrowse").AnchorStyle = enumAnchorStyleTop Or enumAnchorStyleRight
            .Anchor("labDiv1").AnchorStyle = enumAnchorStyleLeft Or enumAnchorStyleRight
            With .Anchor("frame1")
                .AnchorStyle = enumAnchorStyleLeft Or enumAnchorStyleRight Or _
                               enumAnchorStyleBottom Or enumAnchorStyleTop
                .MinimumHeight = 120
            End With
            .Anchor("listbox1").AnchorStyle = enumAnchorStyleLeft Or _
                                              enumAnchorStyleRight Or _
                                              enumAnchorStyleBottom Or _
                                              enumAnchorStyleTop
            With .Anchor("cmdClear")
                .AnchorStyle = enumAnchorStyleBottom Or enumAnchorStyleRight
                .MinimumTop = 90
            End With
            
            .Anchor("labDiv2").AnchorStyle = enumAnchorStyleLeft Or _
                                             enumAnchorStyleRight Or _
                                             enumAnchorStyleBottom
            .Anchor("cmdAbout").AnchorStyle = enumAnchorStyleLeft Or enumAnchorStyleBottom
            .Anchor("checkbox1").AnchorStyle = enumAnchorStyleBottom
            .Anchor("cmdOk").AnchorStyle = enumAnchorStyleBottom Or enumAnchorStyleRight
        End With
        
        ' live updates whilst resizing
        CheckBox1.Value = True
        ListBox1.RowSource = "B12:B19"
    
    'Empty Country
    Country.Value = ""
    
    'Fill CountryBox
    With Country
    .AddItem "Canada"
    .AddItem "USA"
    End With
    
    'Empty LogNumberBox1
    LogNumberBox1.Value = ""
    
    'Empty DivisionListBox
    DivisionListBox.Clear
    
    'Fill DivisionListBox
    With DivisionListBox
    
    .AddItem "Cavendish"
    .AddItem "Construction & Equipment"
    .AddItem "Industrial Security"
    .AddItem "Irving Business Services"
    .AddItem "IT Division"
    .AddItem "Irving Consumer Products"
    .AddItem "Irving Group of Companies (IGM)"
    .AddItem "Irving Personal Care"
    .AddItem "Media"
    .AddItem "Midland"
    .AddItem "Pulp & Paper"
    .AddItem "Retail"
    .AddItem "Sawmills"
    .AddItem "Shipbuilding"
    .AddItem "Transportation and Logistics"
    .AddItem "Universal Properties"
    .AddItem "Woodlands Division"
    .AddItem "Corporate Services"
    .AddItem "Other"
    End With
    
    
    'Empty BusinessUnitListBox
    BusinessUnitListBox.Value = ""
    
    'Fill BusinessUnitListBox
    With BusinessUnitListBox
    .AddItem "Cavendish Agri"
    .AddItem "Cavendish Farms Lethbridge"
    .AddItem "Cavendish Farms"
    .AddItem "Cavendish Produce"
    .AddItem "Island Gas CNG"
    .AddItem "Island Holdings Limited"
    .AddItem "Atlantic Wallboard"
    .AddItem "Fleetway Facility Services"
    .AddItem "Irving Equipment Group"
    .AddItem "Kent Homes"
    .AddItem "Gulf Operators"
    .AddItem "Industrial Security"
    .AddItem "Irving Business Services"
    .AddItem "IT Division"
    .AddItem "Irving Consumer Products"
    .AddItem "Irving Tissue"
    .AddItem "Irving Group Corporate"
    .AddItem "Irving Personal Care"
    .AddItem "Brunswick News"
    .AddItem "Midland"
    .AddItem "Irving Forest Services"
    .AddItem "Irving Paper"
    .AddItem "Irving Pulp & Paper"
    .AddItem "Irving Tissue, Saint John"
    .AddItem "JDI Financial Services"
    .AddItem "Lake Utopia"
    .AddItem "Chandler"
    .AddItem "Kent Building Supplies"
    .AddItem "Plasticraft"
    .AddItem "Sawmills"
    .AddItem "Fleetway Engineering"
    .AddItem "Irving Shipbuilding"
    .AddItem "Halifax Shipyard"
    .AddItem "Atlantic Towing"
    .AddItem "Harbour Development"
    .AddItem "Irving Transportation Services"
    .AddItem "ITS Carriers Inc."
    .AddItem "JDI Logistics"
    .AddItem "Kent Line"
    .AddItem "New Brunswick Southern Railway"
    .AddItem "RST Industries"
    .AddItem "Sunbury Transport Limited"
    .AddItem "Universal Truck & Trailer"
    .AddItem "Universal Properties"
    .AddItem "Woodlands"
    .AddItem "Bayside Realties"
    .AddItem "Evergreen Gardens"
    .AddItem "Irving Air Service"
    .AddItem "St.George Power"
    .AddItem "JDI General Division"
    .AddItem "Irving Shipbuilding-Local 1"
    .AddItem "Irving Shipbuilding-Local 28"
    .AddItem "Shelburne"
    .AddItem "Irving Shipbuilding - Staff"
    .AddItem "Irving Paper-Local 601"
    .AddItem "Irving Paper-Loca l523"
    .AddItem "Irving Paper-Local 30"
    .AddItem "Irving Paper-Local 1888"
    
    End With
    
    'Uncheck ChangeBoxes
    HireBox.Value = False
    RehireBox.Value = False
    TransferBox.Value = False
    PersonalChangeBox.Value = False
    
    'Clear EmployeeInformationBox
     TextBox2.Value = ""
     TextBox3.Value = ""
     
     'Uncheck TypeBoxes
    PlanBox1.Value = False
    PlanBox2.Value = False
    PlanBox3.Value = False
    
    'Clear DateBoxes
    TextBox4.Value = ""
    TextBox5.Value = ""
    TextBox6.Value = ""
    
    'Clear CommentsBox
    CommentsBox.Value = ""
    
    'Uncheck EmploymentBox
    HourlyBox.Value = False
    SalaryBox.Value = False
    
    'Uncheck SpecialistBox
    SpecialistCheckBox1 = False
    SpecialistCheckBox2 = False
    SpecialistCheckBox3 = False
    SpecialistCheckBox4 = False
    SpecialistCheckBox5 = False
    End Sub

  9. #9
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: How Do I make a Userform Resizable or allow it to scroll

    What do you mean by 'stops'? Error happens? Did you create new class called CAnchors in your workbook?

  10. #10
    Registered User
    Join Date
    01-23-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    81

    Re: How Do I make a Userform Resizable or allow it to scroll

    Yeah by stops it gives me an error, it highlights the two top lines and give me a "Compile Error: User-Defined type not defined", and for the new class you lost me there, I am unsure how the class's work, See the class modules and have 2 but they are empty.

  11. #11
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: How Do I make a Userform Resizable or allow it to scroll

    You must copy the code from the Class module in the example to your class and rename the Class to CAnchors, so that it will match the code in your userform. Did you look at the sample workbook on Andy Pope's site?

  12. #12
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: How Do I make a Userform Resizable or allow it to scroll

    what about a more simple zoom approach if your new to coding and classes.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  13. #13
    Registered User
    Join Date
    01-23-2014
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    81

    Re: How Do I make a Userform Resizable or allow it to scroll

    Izandol: I think this may be wayyyy above my skill level right now, I looked at the samplework book and I honestly and am just as confused

    Andy: The zoom approach isn't quite what I would need since the user would have to know to re-size it. I don't think people would figure it out natively like dragging a window like windows does.

  14. #14
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: How Do I make a Userform Resizable or allow it to scroll

    That was to illustrate a point. I was not expecting you to add option buttons to your actual userform.

    This uses the application to determine the screen size and the resizes the userform to be centered in the screen at 90% of screen height.

    It is always best to design your userform with the audience in mind. Just because you have a wide screen monitor do not assume all your users will.
    Same is true for the version of excel and the functionality available. No point in building a solution that users the latest enhancements if the guys using it only have xl2003.
    Attached Files Attached Files

+ 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. [SOLVED] How to make a worksheet scroll using only mouseover
    By treetops in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-13-2012, 10:37 AM
  2. Scroll Bars in VBA userform
    By richardeallen in forum Excel General
    Replies: 1
    Last Post: 07-06-2007, 02:18 PM
  3. userform text box and a scroll bar
    By Shawn in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-17-2006, 04:10 PM
  4. [SOLVED] Can I make the scroll bar show the row number?
    By Marcia Duckworth in forum Excel General
    Replies: 2
    Last Post: 03-23-2005, 11:06 PM
  5. The Query Wizard window should be resizable.
    By Office Spacer in forum Excel General
    Replies: 0
    Last Post: 02-01-2005, 03:06 PM

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