+ Reply to Thread
Results 1 to 31 of 31

Userform - startup position

  1. #1
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Userform - startup position

    Hello,

    I have Userform to display entered data in cells, and needs to be navigated through sheet while entering data. I want Userform to stay at It's last position when I hit "Refresh" button.

    Tried all positions in Startup Property but none works for me, so far best option is to position It to center.

    my "Refresh" button code :

    Please Login or Register  to view this content.
    Any ideas ?

    Thanks in advance !

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Userform - startup position

    Please Login or Register  to view this content.
    David
    (*) Reputation points appreciated.

  3. #3
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Userform - startup position

    Hi Tinbendr,

    Your code probably just sets Userform in center, no need for that as I allready have set that in Property. Although I tried, still the same as before.

    Explanation, again : If I open Userform and change It's position... Then I want this "last" position "remembered" when I hit refresh button, which opens Userform again. I hate when It centers again, kind of annoying when entering data in cells.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Userform - startup position

    Hello Lukae,

    I have some code that will make a UserForm function like a window. Would that work for you ?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Userform - startup position

    I don't know what to say. All I want is that Userform wouldn't move when I close and re-open It. If this does that, than YES OFCOURSE

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Userform - startup position

    Hello Lukael,

    I have had a difficult time staying connected to the forum. Here is the code I promised. Yes, adding this will remember where the UserForm was positioned last while it is open. The default start position is the center of the screen.

    Copy the code below and paste it into a new VBA module in your workbook. Change you UserForm to non-modal by changing the ShowModal property to False.

    Call the macro from the UserForm's Activate event.
    Please Login or Register  to view this content.
    Macro Code To Convert UserForm to Window
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Userform - startup position

    Thanks Leith,

    I pasted code below in new module, set Modal property to False, and pasted this in Userform's code :

    Please Login or Register  to view this content.
    ....And, It's not working. What did I do wrong ?

    So far I had Userform_initialize event, and some code beneath It, so I put that code in _activate event, but nothing happens. It tried with both also

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Userform - startup position

    Hello Lukael,

    Can you post a copy of the workbook for me to review?

  9. #9
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Userform - startup position

    Yes sure, here It is
    Attached Files Attached Files

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Userform - startup position

    Hello Lukael,


    The macro "ConvertToWindow" was not saved in the workbook. I have added the module and tested the workbook. Everything works as it should.
    Attached Files Attached Files

  11. #11
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Userform - startup position

    Quote Originally Posted by Lukael View Post
    Hello,

    I have Userform to display entered data in cells, and needs to be navigated through sheet while entering data. I want Userform to stay at It's last position when I hit "Refresh" button.

    Tried all positions in Startup Property but none works for me, so far best option is to position It to center.

    my "Refresh" button code :

    Please Login or Register  to view this content.
    Any ideas ?

    Thanks in advance !
    This...

    (Explanation: 1. Because you don't know where the user will drag the window too, it is impossible to hard code the positions in the Initialize event. 2. Because you are refreshing your form by Unloading then reloading, all form variables are scrapped so Initialize can't rely on the use of module level variables for the last form positon. However if you have project/global level variables in a standard module then these are not cleared by the form unloading and therefore they can be read by Initialize event when you 'refresh' your form. Easy. )
    Attached Files Attached Files
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  12. #12
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Userform - startup position

    I'm sorry Leith & mc84excel,

    guess like you two didn't fully understand me. I don't even know what your codes do, too complicated for me.

    I tried both solutions, but everything is same as before. So, I will explain again differently :

    This sheet is a monthly schedule for working hours of employees. I assigned one button for Userform which displays all data about entered data for each day and each employee.

    I move opened Userform left/right or up/down (depends on a date and row of employee), because I want to enter data in cells and see the Userfom, both together - this is done by VbModeless command.

    And after a while I want to update Userform with mentioned "refresh" button, so that I can see what data were allready entered. And at that point I want Userform to stay opened where It was before clicking "refresh" button.

    Maybe solutions works for you two, but for me - when I move Userform's position after opening It & then click refresh button, It moves back to center of the screen, as in beginning.

    I have Exel 2003 although, maybe that is problem.

  13. #13
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Userform - startup position

    Hi again,

    I tried both codes again on my home PC and mc84excel's code worked ! Not sure why It didn't on my job PC as I have same Excel 2003 version. Maybe some add-ins missing ?

    Code is exactly what I wanted !!! ....I'm still figuring out how It actually works, despite your explanation everything is still not quite clear to me

    Too bad that I can't check Leith's solution, must be great code too but not sure why nothing happens

    Anyway, mc84excel, thanks for your code, and If this is your masterpiece I must say - You're a genious

  14. #14
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Userform - startup position

    Quote Originally Posted by Lukael View Post
    Anyway, mc84excel, thanks for your code, and If this is your masterpiece I must say - You're a genious
    Glad to help

    If you wish to thank me, you could consider taking a few seconds to rep my post. (Click on the star in the bottom left hand corner of the post).

    If your problem is now solved, please use the Thread Tools (top right hand corner of the page) to mark the thread as SOLVED.


    Quote Originally Posted by Lukael View Post
    mc84excel's code worked ! Not sure why It didn't on my job PC as I have same Excel 2003 version. Maybe some add-ins missing ?
    My code doesn't require any add-ins. Did you run the downloaded workbook on the job PC or was it after you copied the code into your original workbook?

    Quote Originally Posted by Lukael View Post
    I'm still figuring out how It actually works, despite your explanation everything is still not quite clear to me
    I'm happy to explain it in more detail if you want.

  15. #15
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Userform - startup position

    My code doesn't require any add-ins. Did you run the downloaded workbook on the job PC or was it after you copied the code into your original workbook?
    No, in both cases I downloaded file from this forum and tried. On job It didn't work, but on my home PC worked so I pasted code in my original workbook. I will try again on work to see If there is any changes.

    I'm happy to explain it in more detail if you want.
    Yes, I would very like that, I save all my files and try to comment codes so that I learn from It


    If you wish to thank me, you could consider taking a few seconds to rep my post. (Click on the star in the bottom left hand corner of the post).
    DONE !
    Last edited by Lukael; 03-14-2014 at 04:49 PM.

  16. #16
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Userform - startup position

    I tried again on both PC's with same file. At home It works, at job not working. What's wrong, Excel version is same, the only difference I see is that I have Win 7 at home, and XP on work. Is that the case maybe ?

  17. #17
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Userform - startup position

    Oh, and every settings are exact same, even add-ins...

  18. #18
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Userform - startup position

    Quote Originally Posted by Lukael View Post
    I tried again on both PC's with same file. At home It works, at job not working.
    Hi Lukael,

    Sorry to hear it is not working on both machines.

    Quote Originally Posted by Lukael View Post
    What's wrong, Excel version is same, the only difference I see is that I have Win 7 at home, and XP on work. Is that the case maybe ?
    The code relies on two global level variables. ( lngUFpositionTop & lngUFpositionLeft). It works by reading/updating the variable values on the form Initialize event.
    Variables are not dependent on the version of Windows OS or Office so I am puzzled as to why it is not working for you at your job.


    Quote Originally Posted by Lukael View Post
    At home It works, at job not working.
    When you say not working - do you mean that the form doesn't keep the same position after Refresh? Or will the form not even open?

  19. #19
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Userform - startup position

    Quote Originally Posted by Lukael View Post
    Yes, I would very like that, I save all my files and try to comment codes so that I learn from It
    Quick notes below:
    You wanted a user form to keep its position that the end user last dragged it to before hitting Refresh.
    Your refresh code works by Unloading the form and then loading the form again. Doing this causes the Initialize event to fire.
    When a form initializes - the forms position is set using the Top & Left properties (if these are not set, VBA uses a default position)
    However you can also run-time set the forms position in the UserForm_Initialize event (by setting Me.Top and Me.Left).

    So far so good.

    So all we need to do is find a way to write the Top & Left positions after the user drags the form and then read these values back at UserForm_Initialize

    A quick google search revealed that the UserForm_Layout event would cover the user dragging the form. This is the point where you would want to call some code to write the forms current Top & Left positions.

    The question then is how to store these values? There are multiple ways we could do this. But the most simplest way would be to use variables.

    For the purpose of this exercise, they can not be stored in the form (the values of form level variables are lost when a form unloads) so I added two global level variables to a standard module instead.

    When the user drags the form, the UserForm_Layout event fires and updates the two global variables.

    When you open/refresh the form ( UserForm_Initialize ), it checks to see if these global variables are set. If they are then set the forms Top & Left to these values. If they are not set (first time form opened for this session), then write the opening values to the variables.

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

    Re: Userform - startup position

    Why must you close and reopen form? It is better to have routine to reset controls.
    • 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

  21. #21
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Userform - startup position

    Please Login or Register  to view this content.
    Thanks for explanation of code, but I think that I was not wrong. I tested code on 3 different PC's with Win 7 and 4 different PC's with Win XP, with same file. Result was : Win 7 worked, Win XP didn't work.
    That was tested on Excel 2003 and Excel 2007, no PC is connected via network, just separate machines on separate locations.

    Win XP PC's were all SP3, guess like something is wrong there, maybe because of near ending to updates for that OS.

  22. #22
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Userform - startup position

    Quote Originally Posted by Izandol View Post
    Why must you close and reopen form? It is better to have routine to reset controls.
    Hi Izandol, could you give me an example, maybe a sample worksheet ?

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

    Re: Userform - startup position

    With your example workbook, code will be like:
    Please Login or Register  to view this content.

  24. #24
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Userform - startup position

    Hi Izandol,
    I tried on sample and It works but I don't know how to do the code in my workbook as I have more code than in sample provided. Could you take a look at my code and try to do It again ?

    Please Login or Register  to view this content.

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

    Re: Userform - startup position

    This is part you need:
    Please Login or Register  to view this content.

  26. #26
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Userform - startup position

    Thanks, It works !!

    A little bit slower but It does as needed

  27. #27
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Userform - startup position

    Hi,
    Izandol, It's me again.
    Could you explain a little bit this part of code, and how whole code actually works ?


    Please Login or Register  to view this content.

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

    Re: Userform - startup position

    This code will check type of each control on form and reset to default value dependent upon control type.

  29. #29
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Userform - startup position

    Izandol,

    I fully tested your code, but I'm afraid It wasn't working quite as It should. Code actually duplicates records, which is not what I wanted. When I pressed refresh button, It adds another whole lines of names into Listbox, which was not desired, because I have scrollbar on listbox.

    So I had to first clear listbox, now It works !

    Got any clues on how to set comobobox listindex to remain in same value - index after refresh ?
    Last edited by Lukael; 03-23-2014 at 12:26 PM.

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

    Re: Userform - startup position

    You may store value before refresh and reset afterwards. Or do not clear combobox.

  31. #31
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: Userform - startup position

    Hi again,

    I managed to fix my issues in another way. I just populated listbox, textbox and checkboxes on my userform, and leave combobox intacted. And It works excatly as I want

    Thanks for all your help though !!

+ 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. I'm trying to hide my worksheet but have a userform show at startup
    By simeonmein in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-18-2013, 03:29 PM
  2. Control Startup Position of UserForm
    By Mordred in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-13-2011, 01:31 PM
  3. userform as startup object.
    By hexOffender in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-03-2006, 11:49 AM
  4. userform startup splash screen
    By carlito_1985 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-22-2005, 04:05 AM
  5. Re: Userform Position
    By bobkaku in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-19-2005, 08: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