我不知道如何使世界上最简单的可调整大小的UserForm。我在不同的论坛帖子上看到的是可怕的behemots(巨大的宇宙图书馆做得太多)。但我需要一个简单的一笔解决方案,我希望它存在。此刻我有这段代码:
Dim myForm As UserForm1
Set myForm = New UserForm1
myForm.Caption = "Attributes"
myForm.Show
我有UserForm_Initialize()
做了一些额外的工作。什么是可怕的(不合理的?)是默认情况下表单不可调整大小。
答案 0 :(得分:0)
这是一个关于如何使用户形式拖动和重新调整大小的简单指南。
http://www.mrexcel.com/forum/excel-questions/558649-userform-movable-resizable.html
答案 1 :(得分:0)
这是从
转录的解决方案https://www.mrexcel.com/board/threads/resize-a-userform.485489/
我已经测试过它并且有效
首先将这些声明添加到您的标题中
'Declaration for form resize
Private Declare Function GetActiveWindow Lib "user32.dll" () As Long
Private Declare Function SetLastError Lib "kernel32.dll" (ByVal dwErrCode As Long) 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 Sub MakeFormResizable()
'Written: August 02, 2010
'Author: Leith Ross
'Summary: Makes the UserForm resizable by dragging one of the sides. Place a call
' to the macro MakeFormResizable in the UserForm'
'from https://www.mrexcel.com/board/threads/resize-a-userform.485489/
Dim lStyle As Long
Dim hWnd As Long
Dim RetVal
Const WS_THICKFRAME = &H40000
Const GWL_STYLE As Long = (-16)
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)
'Clear any previous API error codes
SetLastError 0
'Did the style change?
If RetVal = 0 Then MsgBox "Unable to make UserForm Resizable."
End Sub
最后从你的 Userform_Activate 调用这个子
Private Sub UserForm_Activate()
MakeFormResizable
End Sub