Stretching a userform with the mouse

P

Pierre Archambault

Hi,

I have a workbook that uses a userform to display some help text. (.pdf)

I use the "WebBrowser" control to do so. I set a default size of 640 x 480
for the userform. However I would like the user be able to modify the window
size the way we usually do: stretching it by the lower right corner.

If someone could help me with that challenge, I would appreciate.

Thanks

Pierre
 
L

Leith Ross

Hello Pierre,

Add a new VBA module to your project and copy the following code into
it.

CALLING THE FORM RESIZE CODE:
In the UserForm Activate event add the following line...

Call MakeFormResizable


Code:
--------------------

'API calls and constants
'
'Returns the Window Handle of the Active Window
Public Declare Function GetActiveWindow _
Lib "User32.dll" () As Long

Private Declare Function GetWindowLong _
Lib "User32.dll" _
Alias "GetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long) As Long

Private Declare Function SetWindowLong _
Lib "User32.dll" _
Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

Private Const GWL_STYLE As Long = (-16) 'The offset of a window's style
Private Const WS_THICKFRAME As Long = &H40000 'Style to add a sizable frame

Public Sub MakeFormResizable()

Dim lStyle As Long
Dim hWnd As Long
Dim RetVal

hWnd = GetActiveWindow

'Get the basic window style
lStyle = GetWindowLong(hWnd, GWL_STYLE) Or WS_THICKFRAME

'Set the basic window styles
RetVal = SetWindowLong(hWnd, GWL_STYLE, lStyle)

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top