Create a Button to open the Excel
UserForm
To make it easy for users to open the UserForm, you can add a button
to a worksheet.
- Switch to Excel, and activate the PartLocDB.xls workbook
- Double-click on the sheet tab for Sheet2
- Type: Parts Data Entry
- Press the Enter key
- On the Drawing toolbar, click on the Rectangle tool
- In the centre of the worksheet, draw a rectangle, and format as
desired.
- With the rectangle selected, type:
Click here to add Part
Information
- Right-click on the rectangle border, and choose 'Assign Macro'
- Click the New button
- Where the cursor is flashing, type: frmPartLoc.Show
Note:
If you are using Excel 2000, or later version, and want users to
be able to do other things while the form is open, change the above
line to: frmPartLoc.Show False
To prevent users from closing the form by clicking the X
button:
- Right-click on an empty part of the UserForm
- Choose View | Code
- Scroll to the bottom of the existing code, and enter the following
code:
Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please use the button!"
End If
End Sub
- On the Menu bar, choose View | Object, to return to the UserForm.
|

|