Remove The Caption Bar From A User Form


June 16, 2021 - by

Remove The Caption Bar From A User Form

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:


e9781615474011_i0286.jpg
e9781615474011_i0287.jpg


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).

Figure 143. You can create a user form that doesn’t have a red X close button.
Figure 143. You can create a user form that doesn’t have a red X close button.

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.