Showing a UserForm from the VBE

There are at least two ways to show a userform from within the VBE. The easy method is to hide the main Excel application. The userform will still be a child of the main Excel window, but nobody will be the wiser. That is, except when their Excel and VBE windows have switched positions on the taskbar.

The more complicated method uses the FindWindow and SetParent APIs. It’s only real benefit is that it doesn’t reorder the windows in the taskbar, but it’s not really that much more complicated, so I prefer it. It sets the userform’s window as a child of the VBE window instead of as a child of Excel’s main window.

3 thoughts on “Showing a UserForm from the VBE

  1. The hwnd of the VBE Window can also be got from Application.VBE.MainWindow.hWnd, which is safer if you have more than one VBE open at the same time (e.g. Excel and Word, or two Excels)!

    Regards

    Stephen Bullen


Posting code? Use <pre> tags for VBA and <code> tags for inline.

Leave a Reply

Your email address will not be published.