|
-
Nov 21st, 1999, 09:45 PM
#1
Thread Starter
Fanatic Member
Anyone know how I can find the screen height and width in VBA? I want to make a form fill the screen.
-
Nov 21st, 1999, 10:18 PM
#2
Member
To find the screen's height in twips:
Code:
Screen.Width
Screen.Height
To find it in pixels:
Code:
Screen.Width / Screen.TwipsPerPixelX
Screen.Height / Screen.TwipsPerPixelY
------------------
(¯`·.¸¸.·´¯`·->ShadowCrawler<-·´¯`·.¸¸.·´¯)
Teenage Programmer
Visual Basic, HTML, C++, JavaScript
http://welcome.to/X12Tech
Email: [email protected]
ICQ#: 9872708
-
Nov 21st, 1999, 10:37 PM
#3
Thread Starter
Fanatic Member
Sorry ShadowCrawler, I'm talking VBA here, not the real thing. It doesn't recognise the Screen object. Any thoughts? (I'm sure you all have many thoughts, most of them unprintable, but hey...)
-
Nov 21st, 1999, 10:57 PM
#4
I'm sure there has to be a better way but this works for me (in word 2000).
Code:
Option Explicit
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub ScreenSize()
Dim ScreenRect As RECT
Dim ret As Long
ret = GetClientRect(CLng(GetDesktopWindow()), ScreenRect)
MsgBox "Width: " & ScreenRect.Right - ScreenRect.Left
MsgBox "Height: " & ScreenRect.Bottom - ScreenRect.Top
End Sub
Private Sub Document_New()
ScreenSize
End Sub
------------------
Vincent van den Braken
EMail: [email protected]
ICQ: 15440110
Homepage: http://www.azzmodan.demon.nl
-
Nov 22nd, 1999, 05:05 PM
#5
Thread Starter
Fanatic Member
Thanks Azzmodan, that works great - you're a star
-
May 10th, 2016, 05:55 AM
#6
Member
Re: VBA, screen width/height?
Code:
Private Declare Function GetSystemMetrics32 Lib "User32" Alias "GetSystemMetrics" (ByVal nIndex As Long) As Long
Private Sub UserForm_Activate()
Me.Height = GetSystemMetrics32(1)
Me.Width = GetSystemMetrics32(0)
End Sub
Sorry for the late post but I only had almost 1 year when you posted this
When someone talks sh*t about me:
Are you ta'king to me?..
Are you ta'king to the special one?..
Are you ta'king to the special one?..
There's nobody else here,
you must be talking to the special one!
Are you ta'king to me?
Are are, are you ta'king to me?

-
May 10th, 2016, 06:01 AM
#7
Re: VBA, screen width/height?
No need to alias GetSystemMetrics(), and magic numbers are an annoying newb hack. Define the appropriate constants (see GetSystemMetrics function).
-
May 10th, 2016, 08:59 AM
#8
Re: VBA, screen width/height?
A 17 year old question 
"Magic Numbers" are hard to read and really should not be used but I do not know that they are a sign of a newb and definitely not a hack.
I remember when I first started many many years ago, you either used "magic numbers" or you created your own constants. Constants made the code easier to read at the expense of less available lines for processing.
Now of course we are well past the days where we needed to worry so much about how many bytes our code was using but for some programmers it is habit to use numbers directly in some cases, especially when using more than one language where the constant names are all different.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|