Douken Posted March 27, 2018 at 10:34 AM Report #609936 Posted March 27, 2018 at 10:34 AM Bom dia. Eu criei um aplicativo em vba Excel que será usado em computadores distintos. O problema disto é que o UserForm é grande, o que faz com que nos monitores mais pequenos não se consiga utilizá-lo adequadamente. Assim, eu tenho procurado por um código que permita ajustar o tamanho do Userform e respetivo conteúdo à resolução do monitor. Andei à procura na internet e encontrei alguma coisa, mas nenhum dos códigos que encontrei está preparado para 32 e 64 bit. Este pareceu-me interessante: Option Explicit 'Function to get screen resolution Private Declare Function GetSystemMetrics32 Lib "user32" Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long 'Functions to get DPI Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, ByVal nIndex As Long) As Long Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hDC As Long) As Long Private Const LOGPIXELSX = 88 'Pixels/inch in X Private Const POINTS_PER_INCH As Long = 72 'A point is defined as 1/72 inches 'Return DPI Public Function PointsPerPixel() As Double Dim hDC As Long Dim lDotsPerInch As Long hDC = GetDC(0) lDotsPerInch = GetDeviceCaps(hDC, LOGPIXELSX) PointsPerPixel = POINTS_PER_INCH / lDotsPerInch ReleaseDC 0, hDC End Function 'Resize when Userform Initialize Private Sub UserForm_Initialize() Dim w As Long, h As Long w = GetSystemMetrics32(0) ' Screen Resolution width in points h = GetSystemMetrics32(1) ' Screen Resolution height in points With Me .StartUpPosition = 1 .Width = w * PointsPerPixel * 0.85 'Userform width= Width in Resolution * DPI * 85% .Height = h * PointsPerPixel * 0.85 'Userform height= Height in Resolution * DPI * 85% End With End Sub Será que alguém me pode ajudar a torná-lo compatível com vba7? Ou então, poderiam propor-me um código alternativo? Cumprimentos e obrigado!
manuel antonio Posted April 2, 2018 at 10:18 PM Report #610033 Posted April 2, 2018 at 10:18 PM Boa noite. Tenta ver se o conteúdo deste Link ajuda. http://www.macoratti.net/dica4.htm
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now