modifying a fullscreen userform macro

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
I found this code here in this forum which maximizes the userform to cover the whole screen. It worked for me but I have a multi page form and the multi page did not expand. So I wanna know if it can also expand as well. Then what happens to the controls on it. Will they too expand?
Code:
Option Explicit

[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=If]#If[/URL]   VBA7 Then
    Private Declare PtrSafe Function WindowFromAccessibleObject Lib "oleacc" (ByVal pacc As IAccessible, phwnd As LongPtr) As Long
    Private Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
    Private Declare PtrSafe Function SetWindowPos Lib "user32" (ByVal hwnd As LongPtr, ByVal hWndInsertAfter As LongPtr, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Private Declare PtrSafe Function IsWindow Lib "user32" (ByVal hwnd As LongPtr) As Long
    Private hwnd As LongPtr
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=Else]#Else[/URL]   
    Private Declare Function WindowFromAccessibleObject Lib "oleacc" (ByVal pacc As IAccessible, phwnd As Long) As Long
    Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
    Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Private Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
    Private hwnd As Long
[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=End]#End[/URL]   If

Private Const SM_CXSCREEN = 0
Private Const SM_CYSCREEN = 1

Private Sub UserForm_Initialize()
    Call WindowFromAccessibleObject(Me, hwnd)
    If IsWindow(hwnd) Then
        SetWindowPos hwnd, 0, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), 0
    End If
End Sub

And also on my pc the lines after the #Else are lighted red and was prompted to update them and mark them as PtrSafe. Somebody help me out.
Kelly
 
Oh okay thanks very much for it. I am very grateful.

There is one issue with the listbox: the columns did not expand to match the data it contains.
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Oh okay thanks very much for it. I am very grateful.

There is one issue with the listbox: the columns did not expand to match the data it contains.

Good point ... Never thought about the listbox\combobox dropdown .. I'll see if I can find a solution and post back later.
 
Last edited:
Upvote 0
I have just tried populating a listbox as well as a combobox on the useform and the data in both of them expands just fine :

Are you refering to a multi-column listbox ?
 
Upvote 0
Yes multi column. I have 14 columns. When we used the Me.Zoom it worked fine. The listbox itself expands well but the columns don't

Comboboxes worked for me too.
 
Last edited:
Upvote 0
Yes multi column. I have 14 columns. When we used the Me.Zoom it worked fine. The listbox itself expands well but the columns don't

Comboboxes worked for me too.

I have just added a multi-column listbox with 3 columns for testing and everything works as expected ... the listbox expands as do the listbox columns ... I can see the columns have expanded when scrolling the listbox horizontally

So I don't really know the reason the columns don't expand for you.
 
Last edited:
Upvote 0
I have just added a multi-column listbox with 3 columns for testing and everything works as expected ... the listbox expands as do the listbox columns ... I can see the columns have expanded when scrolling the listbox horizontally

So I don't really know the reason the columns don't expand for you.

Okay I am about to delete the column widths and see
 
Upvote 0
I think it is not expanding because I have the column widths personalised. When I deleted the personalized one, it expanded well but the contents did not fit well in the spaces
 
Upvote 0
Is there a way to get this issue resolved?
Maybe some if statement will do. That's the if statement will run only when I maximize the userform. I just can't figure how to place it yet.
Kelly
 
Last edited:
Upvote 0
Is there a way to get this issue resolved?
Maybe some if statement will do. That's the if statement will run only when I maximize the userform. I just can't figure how to place it yet.
Kelly

Can you upload a workbook demo somewhere like box.net or other file- sharing site so I can see what problem you are having ?
 
Upvote 0
Hello Jaafar Tribak,
Can you please pm me your email so I can send the demo to you? I am having problems uploading to the Dropbox
Kelly
 
Upvote 0

Forum statistics

Threads
1,223,713
Messages
6,174,043
Members
452,542
Latest member
Bricklin

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