?
Solved

How can I find out the screensize?

Posted on 2004-09-17
7
Medium Priority
?
277 Views
Last Modified: 2010-05-02
Hi
I need to find out the computers screensize from my excel- document (excel2000), and from that decide the zoom- factor of the spreadsheet.
How can I do that?

Mats
0
Comment
Question by:hucklberry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 400 total points
ID: 12089319
Here is one way to determine the screen resolution:

Option Explicit

Private Type RECT
    x1 As Long
    y1 As Long
    x2 As Long
    y2 As Long
End Type

Private Declare Function GetDesktopWindow Lib "User32" () As Long
Private Declare Function GetWindowRect Lib "User32" (ByVal hWnd As Long, rectangle As RECT) As Long

Private Sub foo()
    Dim screenRect As RECT
    Dim hWnd As Long
    Dim ret As Long
    Dim screenWidth As Long
    Dim screenHeight As Long
    Dim resolution As String
   
    hWnd = GetDesktopWindow()
    ret = GetWindowRect(hWnd, screenRect)
    screenWidth = screenRect.x2 - screenRect.x1
    screenHeight = screenRect.y2 - screenRect.y1
    resolution = screenWidth & "x" & screenHeight
    MsgBox resolution
End Sub
0
 
LVL 32

Assisted Solution

by:Erick37
Erick37 earned 300 total points
ID: 12089467
Or...

Declare Function GetSystemMetrics Lib "User32" (ByVal nIndex As Long) As Long

Const SM_CXSCREEN As Long = 0
Const SM_CYSCREEN As Long = 1

Public Property Get ScreenHeight() As Long
   ' Return screen height in pixels.

   ScreenHeight = GetSystemMetrics(SM_CYSCREEN)
End Property

Public Property Get ScreenWidth() As Long
   ' Return screen width in pixels.
   
   ScreenWidth = GetSystemMetrics(SM_CXSCREEN)
End Property

from:
Office VBA and the Windows API
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnofftalk/html/office03082001.asp
0
 
LVL 76

Expert Comment

by:David Lee
ID: 12089503
Here's another.  This uses WMI (Windows Management Instrumentation) to get that info.  If there are multiple video cards in the system, which is unusual, then this query would return multiple video records.  The Function would then need to be modified.

Private Function GetScreenResolution() As String
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_VideoConfiguration",,48)
    objItem.HorizontalResolution & "x" & objItem.VerticalResolution
End Function
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 53

Expert Comment

by:Ryan Chong
ID: 12089654
or look for the Screen.Width / Screen.TwipsPerPixelX and Screen.Height / Screen.TwipsPerPixelY:

Public Type POINTAPI
   X As Long
   Y As Long
End Type

Public Sub GetResolution(ByRef res As POINTAPI)
    res.x = Screen.Width / Screen.TwipsPerPixelX
    res.y = Screen.Height / Screen.TwipsPerPixelY
End Sub

then

Dim myRes As POINTAPI
GetResolution myRes

msgbox myRes.x & " x " & myRes.y
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12089747
I don't believe the Screen object is available in VBA.
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 12089803
ah... Erick you're right, didn't read question clearly..

Disregard my comment and try other experts examples. cheers
0
 

Author Comment

by:hucklberry
ID: 12090808
Thanks for your help!
The solutions from IdleMind and Erik37 both worked fine. Hope that it's ok to split the points between you (IdleMind was first,thats why I gave him/her 100p).

BlueDevilFan's solution didn't work for me for some reason.

mats
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month12 days, 9 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question