Office VBA class to keep UserForms on top of SDI Windows.
This is essentially a republish of Jan Karel Pieterse’s article https://jkp-ads.com/articles/keepuserformontop02.asp. So all credits go to him!
The main reason for this repository is to bundle all improvements at one point. Otherwise one has at least to dig through all the comments below the article to find them.
-
Keep a UserForm on top of SDI Windows[1]
Since this is an Office class you obviously need Microsoft Office (single components of that bundle like Excel).
Add the file(s) from the src folder to your project. Yes, it’s that simple.
If you need some more advice on how to do that, expand me.
-
Open Microsoft Excel.
-
Open the Visual Basic Editor (VBE) (Alt+F11).
-
Add the file(s) in the src folder to your VBA project.
-
With Rubberduck:
-
Right-click on the project to which you want to add the file(s) in the “Code Explorer” (to show it press Ctrl+R) and click on Add › Existing Files….
-
Select all files in the src folder and click on Open.
-
-
Without Rubberduck:
-
Select all files in the src folder in Windows File Explorer.
-
Drag-and-drop them to the corresponding project in VBE’s “Project Explorer”.
(To show it press Ctrl+R. Hit it twice if the Code Explorer shows up first.)
-
-
-
Check, if there are obvious errors by compiling the project (Debug › Compile ‹project name›).
-
Save the file/project.
-
Be sure that the file/project you want to save is “active” in the VBE by checking, if its name is shown in VBE’s title bar.
(If it’s not, open a (class) module of the corresponding project (and close it again).) -
Press the “Save” button (the disc symbol similar to 💾) in VBE’s toolbar.
-
Check that the file (really) was saved by having a look at the “last modified date” of the (project) file in the Windows File Explorer.
-
Add
Private mclsFormOnTop As cFormOnTop
Private Sub UserForm_Initialize()
Set mclsFormOnTop = New cFormOnTop
Set mclsFormOnTop.TheUserform = Me
mclsFormOnTop.InitializeMe
End Subto your UserForm code. (This is the given example from the original article.)
If you want to see it in action, you can also have a look at the example(s) given in the demo folder.
Unfortunately we don’t know how to create automated tests/unit tests for this project. If you have an idea, we would love to see it! Please add an issue or – even better – a pull request (see Contributing).
But of course one can manually test it. Please have a look at the demo folder.
This project is used by (at least) these projects:
If you know more, we will be happy to add them here.
All contributions are highly welcome!!
If you are new to git/GitHub, please have a look at https://github.com/firstcontributions/first-contributions where you will find a lot of useful information for beginners.
We recently were pointed to https://www.conventionalcommits.org which sounds very promising. We will use them from now on too (and hopefully don’t forget it in a hurry).
-
What are the
'@...comments good for in the code?You should really have a look at the awesome Rubberduck project!