Remove The Caption Bar From A User Form
June 16, 2021 - by Bill Jelen
Challenge: You want to show a user form in Excel and prevent users from closing the form by clicking the red X close button in the corner.
Solution: You can hide the caption bar—and therefore also the red X close button—in a user form. Doing so requires a bit of Windows API.
One problem is that no one can move the form if the caption is missing. The last bit of code in the macro below therefore uses the MouseDown method to allow the form to be moved.
In VBA, you select Insert Userform. Draw one button on the form (or users won’t have any way to close the form!). Right-click the form and choose View Code. Paste the following code into the code pane for the form:
When you run the macro, you have a user form that must be dismissed using the button on the form instead of using the red X close button (Figure 143).
Summary: You can prevent the red X close button from appearing in a user form.
Source: Captionless UserForm on the MrExcel Message Board.
Title Photo: Badiuth on Unsplash
This article is an excerpt from Excel Gurus Gone Wild.