+ Reply to Thread
Results 1 to 9 of 9

VBA and Screen video resolution

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-03-2005
    Posts
    315

    VBA and Screen video resolution

    What is the right syntax to set screen video resolution. I need this to scale a userform relative to a user's setting. For an illustration,

    IF Application.Windows.Vidwith = 800 And _ 
    Application.Windows.vidHeight=600 Then
    
    Me.Height=75
    Me.Width=60
    
    ElseIf Application.Windows.Vidwith = 1024 And _ 
    Application.Windows.VidHeight=876 Then
    
    Me.Height=75*1.3
    Me.Width=60*1.3
    Me.Zoom=130
    
    End if
    TIA

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885
    Hi davidm,

    Try something like this code into the form's initialize event:
    Private Sub UserForm_Initialize()
    Dim w As Long, h As Long
        w = GetSystemMetrics32(0) ' width in points
        h = GetSystemMetrics32(1) ' height in points
        
        If w = 800 And h = 600 Then
            Me.Width = 75
            Me.Height = 60
        ElseIf w = 1024 And h = 768 Then
            Me.Width = 75 * 3
            Me.Height = 60 * 2
            Me.Zoom = 130
        ElseIf w = 1280 And h = 1024 Then
            Me.Width = 75 * 4
            Me.Height = 75 * 3
            Me.Zoom = 200
        Else
            MsgBox "What kind of resolution are you using?!?"
        End If
        End Sub
    And this code in a standard module:
    Declare Function GetSystemMetrics32 Lib "User32" _
        Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long

  3. #3
    Forum Contributor
    Join Date
    03-03-2005
    Posts
    315
    Many thanks Paul. It worked it a treat! I had all the time sensed the solution might require a Windows API call but couldn't quite figure how to get round it. Once again, many thanks.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    If you intend adjusting the UserForm size according to the screen rewsolution, how are you going to re-position/ rezize controls on the UserForm?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243
    hi all

    It looks like there are still some problems with the site, eh Roy?

    Repetition, repetition, repetition is the key!
    ;-)

    Sorry, I couldn't help myself after having 1/2 a dozen errors myself, this made me chuckle & I've probably done the same thing on other threads tonight.

    :-)
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Quote Originally Posted by broro183
    hi all

    It looks like there are still some problems with the site, eh Roy?

    Repetition, repetition, repetition is the key!
    ;-)

    Sorry, I couldn't help myself after having 1/2 a dozen errors myself, this made me chuckle & I've probably done the same thing on other threads tonight.

    :-)
    Rob
    Hi Rob

    I spent ages trying to post the item, then it posted it 3 times. Then I spent a similar amount of time trying to delete the extra ones!

    It is getting too frustrating here, if it doesn't get sorted soon I won't bother. I'll stick to my site & it's Forrum!

  7. #7
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885
    Roy,

    I think the 'Me.Zoom =' lines handle "resizing" the controls when the form size is changed. The zoom numbers I put in the code were just for example.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1