Notifications
Clear all

Redimensionar userform de acordo com a resolução da tela

2 Posts
2 Usuários
0 Reactions
1,133 Visualizações
(@ma-rsouza)
Posts: 0
New Member
Topic starter
 

Boa noite, pessoal! Sou novo no forum e tenho uma duvida sobre como posso fazer para redimensionar um userform (VBA) em tempo de execuçao de acordo com a resolução da tela / monitor, pois tive problemas ao usar uma planilha em outro pc com resoluçao diferente. Sera que alguem pode me ajudar? Desde já agradeço a atenção. dispensada Obrigado!

 
Postado : 22/09/2016 7:33 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa tarde!!

Se o caso form redimensionar, tente o código de Leith Ross.

Private Sub UserForm_Activate()
  MakeFormResizable
End Sub



'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's Activate event.

 Private Declare Function SetLastError _
   Lib "kernel32.dll" _
     (ByVal dwErrCode As Long) _
   As Long
   
 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

Public Sub MakeFormResizable()

  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

Att

 
Postado : 23/09/2016 9:59 am