Microsoft Office Tutorials and References
In Depth Information
A Resizable UserForm
Private Sub Image1_MouseMove(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Call NoRaise
Image1.SpecialEffect = fmSpecialEffectRaised
End Sub
This procedure calls the NoRaise procedure, which turns off the raised special effect for each
Private Sub NoRaise()
‘ Remove the raised effect from all controls
Dim ctl As Control
For Each ctl In Controls
ctl.SpecialEffect = fmSpecialEffectFlat
Next ctl
End Sub
The net effect is that the user gets some visual feedback when the mouse moves over a control —
just like a real toolbar. The toolbar simulation only goes so far, however. You can’t resize the
UserForm (for example, make the images display vertically rather than horizontally). And, of
course, you can’t dock the pseudo-toolbar to one of the Excel window borders.
The images displayed on the controls are characters from the Wingding font. I used
Excel’s Insert➜Text➜Symbol command to enter the character into a cell. Then I copied
it to the Clipboard and pasted it into the Picture property in the Properties box. This
is a quick and easy way to add images to UserForm controls.
A Resizable UserForm
Excel uses several resizable dialog boxes. For example, you can resize the Name Manager dialog
box by clicking and dragging the bottom-right corner.
If you’d like to create a resizable UserForm, you’ll quickly discover that there’s no direct way to
do it. One solution is to resort to Windows API calls. That method works, but it’s complicated to
set up. In addition, that method doesn’t generate any events, so your code can’t respond when
the UserForm is resized. In this section, I present a much simpler technique for creating a
userresizable UserForm.
Credit for this technique goes to Andy Pope, an Excel expert and Microsoft MVP who
lives in the UK. Andy is one of the most creative Excel developers I’ve ever met. For a
real treat (and interesting downloads), visit his Web site at .
Search JabSto ::

Custom Search