+ Reply to Thread
Results 1 to 6 of 6

Keep userform on top

  1. #1
    Registered User
    Join Date
    08-28-2008
    Location
    bournemouth
    MS-Off Ver
    Office 2007
    Posts
    42

    Keep userform on top

    Hi

    I have written a VBA code in AutoCAD to export information to excel,

    Is there a way I can keep userforms on top of all application windows (i.e Always show)

    Hope someone can help

    Streng

  2. #2
    Registered User
    Join Date
    08-28-2008
    Location
    bournemouth
    MS-Off Ver
    Office 2007
    Posts
    42

    Re: Keep userform on top

    I am thinking that Windows API is the way forward - Any Suggestions ?

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

    Re: Keep userform on top

    Hello Streng,

    Copy this code into a Standard VBA module. Place the macro KeepFormOnTop in the UserForm's Activate event module.
    Please Login or Register  to view this content.
    Example
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 05-19-2009 at 01:48 PM.
    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!)

  4. #4
    Registered User
    Join Date
    08-28-2008
    Location
    bournemouth
    MS-Off Ver
    Office 2007
    Posts
    42

    Re: Keep userform on top

    Thanks but still having trouble that the userform is still attached to AutoCAD, when I click on the userform it brings CAD to the top.
    Will have to rethink my code.

  5. #5
    Registered User
    Join Date
    07-13-2010
    Location
    Brisbane, Australia
    MS-Off Ver
    64 bit 2019
    Posts
    8

    Re: Keep userform on top

    Thanks Leith, this is the first code that I have been able to get to work for me (64 bit machine).
    I had to modify it as follows:
    Replace the 2 lines beginning "Const..." with the following lines:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-13-2010
    Location
    Brisbane, Australia
    MS-Off Ver
    64 bit 2019
    Posts
    8

    Re: Keep userform on top

    I have found a way to make my forms come to the top when I load them, and still behave “normally”. I have tried to do this a number of times in the past with different API functions, but always had negative/mixed results. This works well for me but it may or may not work for you – you will have to test it and see:


    (1) At the top of a normal module (I think a form module is OK too):

    Please Login or Register  to view this content.
    I think Private can be changed to Public if it is to be called from different modules.


    (2) I use Form1.Show but you may use a different command to display your form. Then to make it on top:
    Please Login or Register  to view this content.

    (3) Dimension the handle as public
    Please Login or Register  to view this content.

    (4) To get the handle, I use this code in the Initialize sub for the Form1 module:
    Please Login or Register  to view this content.

    Only minor but, I have never been able to SetFocus to the form so as to highlight it. If anyone has worked out how to do that …..

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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