Adjust Size - UserForm TextBoxes in Taskbar

adavid

Board Regular
Joined
May 28, 2014
Messages
145
The textbox fields of my UserForm are too long, but only when I click the taskbar icon. When UserForm displays after clicking the taskbar icon, then textbox fields run over everything to the right. How do I adjust the textbox size?
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
I don't get a taskbar icon for a userform, just the icons for the open workbooks. Have you tried adding code to set the text box size in the "UserForm_Activate" event to correct the problem?
 
Upvote 0
I don't get a taskbar icon for a userform, just the icons for the open workbooks. Have you tried adding code to set the text box size in the "UserForm_Activate" event to correct the problem?

You wouldn't have a taskbar icon for a UserForm unless you coded it in. The problem I was experiencing was due to the width of one of the columns on the document itself. The column width of one column was causing all of the fields of the UserForm Icon to be one width and consequently was overlapping the other information on the window.
 
Upvote 0
Could you please provide the code to place a userform icon in the taskbar.
Code:
Option Explicit
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetFocus Lib "user32" (ByVal hWnd As Long) As Long
Private Const GWL_STYLE As Long = -16
Private Const GWL_EXSTYLE As Long = -20
Private Const WS_CAPTION As Long = &HC00000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const WS_POPUP As Long = &H80000000
Private Const WS_VISIBLE As Long = &H10000000
Private Const WS_EX_DLGMODALFRAME As Long = &H1
Private Const WS_EX_APPWINDOW As Long = &H40000
Private Const SW_SHOW As Long = 5
Code:
Private Sub UserForm_Activate() 'note that there is icon pertinent code in my UserForm Active Sub
'Application.Visible = False
'Application.VBE.MainWindow.Visible = False
    Dim lngHwnd As Long
    Dim lngCurrentStyle As Long, lngNewStyle As Long
    
    With UserForm2
        .StartUpPosition = 0
        .Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
        .Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
    End With
    
    If Val(Application.Version) < 9 Then
        lngHwnd = FindWindow("ThunderXFrame", Me.Caption)  
    Else
        lngHwnd = FindWindow("ThunderDFrame", Me.Caption)  
    End If
    'Set the Windows style so that the userform has a minimise and maximise button
    lngCurrentStyle = GetWindowLong(lngHwnd, GWL_STYLE)
    lngNewStyle = lngCurrentStyle Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX
    lngNewStyle = lngNewStyle And Not WS_VISIBLE And Not WS_POPUP
    SetWindowLong lngHwnd, GWL_STYLE, lngNewStyle
    'Set the extended style to provide a taskbar icon
    lngCurrentStyle = GetWindowLong(lngHwnd, GWL_EXSTYLE)
    lngNewStyle = lngCurrentStyle Or WS_EX_APPWINDOW
    SetWindowLong lngHwnd, GWL_EXSTYLE, lngNewStyle
    ShowWindow lngHwnd, SW_SHOW
End Sub
Code:
Sub MakeFormResizable()
    Dim UFHWnd As Long    ' HWnd of UserForm
    Dim WinInfo As Long   ' Values associated with the UserForm window
    Dim R As Long
    Const GWL_STYLE = -16
    Const WS_SIZEBOX = &H20000
    Const WS_USER  As Long = &H4000
    Load UserForm1  ' Load the form into memory but don't make it visible
    UFHWnd = FindWindow("ThunderDFrame", UserForm1.Caption)  ' find the HWnd of the UserForm
    If UFHWnd = 0 Then
        ' cannot find form
        Debug.Print "UserForm not found"
        Exit Sub
    End If
    
    WinInfo = GetWindowLong(UFHWnd, GWL_STYLE)      ' get the style word (32-bit Long)
    WinInfo = WinInfo Or WS_SIZEBOX                 ' set the WS_SIZEBOX bit
    R = SetWindowLong(UFHWnd, GWL_STYLE, WinInfo)   ' set the style word to the modified value.
    UserForm1.Show
End Sub
 
Upvote 0
In the Sub I think this:
Const WS_SIZEBOX = &H20000
has to be change to this:
Const WS_SIZEBOX = &H40000
to make the form resizeable
 
Upvote 0

Forum statistics

Threads
1,214,807
Messages
6,121,679
Members
449,047
Latest member
notmrdurden

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top