Resizable userform.

  • Received some awesome help for an issue yesterday - hoping someone is good enough to help me with another item on my wish list.


    I have multiple userforms in an Excel project, some of these are fixed size and fairly static, but a couple are used for note entry - what I would like to do is make these userforms more like a real Windows forms with resizable borders and controls. I understand resizing the controls is coded in the Userform_Resize event but if the window is not resized, the code never runs. Also, I don't want to 'zoom' the controls but instead resize them to fit whatever size the userform is.


    A normal Window can be resized by clicking on the Border and dragging, but not VBA userforms unless they are modified somehow using the Windows API - I've looked into this but it's totally beyond me. I get the fact the SENDMESSAGE function is used but any more than that causes me endless pain.


    Is it possible to have resizable userforms without being a rocket scientist?

  • Re: Resizable userform.


    Quote

    Is it possible to have resizable userforms without being a rocket scientist


    Yes - there's 2 ways to do this - you learn or you ape.


    If you want to learn I'll explain the steps (and SendMessage does not appear in them, at all) and you can try to build it yourself from some skeleton code or I can just upload some code you'll probably use a lot but never look at.


    Your choice...

  • Re: Resizable userform.


    If you have the time then Number 1, please.


    I would try and pick apart any code you post, but I think it would be more useful if I tried to put it together to start with.

  • Re: Resizable userform.


    In the attached the user form has edges that the user can drag to their liking.
    The clsResiseBorders object has different properties that you can adjust to your taste. The demo use form control set some of those properties.

    Files

    • moveEdge.xlsm

      (116.93 kB, downloaded 319 times, last: )
  • Re: Resizable userform.


    The key section is where the MouseDown and MouseMove events (?in clsResizeBorder?) adjust things.
    Its been a while since I've written that. Left on my "to do" list is adding code to have the UF remember its size and location between invocations.

  • Re: Resizable userform.


    I decided on option number 2 :)


    Attached sample uses the Windows API to make the userform resizable. 2 sample controls, both textboxes. One is a standard textbox that resizes to fit the width the other is a multiline textbox that resizes vertically and horizontally.