Screen Resolution

R

Ronbo

I have created a workbook/worksheets using a monitor with 1280 x 1024
resolution. My worksheets were developed to perfectly fit the screen. But
when someone else uses it they may not have 1280 x 1024 resolution... say
1024 x 768. In this case part of the worksheet is out side of the screen.

Info that I got from this group says not to change someone elses screen
resolution. So what I want to do is when the workbook opens it checks the
screen resolution of the compter and then adjusts the "Zoom" to the
appropiate level so that the worksheet will fit on the screen. For example
if it 1024 x 768 it would set the "Zoom" to 75%.

Secondly, is there a chart with "Zoom" levels for differant resolutions and
is it possible to set resolutions such as 73%? Mine seems to defult to (or
be the same) as 75%.

Any help on how to do this would be appreciated.

Thanks
 
T

Tom Ogilvy

You know the range you want to show, so

Range("A1:M20").Select
ActiveWindow.Zoom = True
 
R

Ronbo

Tom:

This works somewhat but with problems. First of all if I use macro buttons
to change worksheets it works, but if I use sheet tabs it gives me a
completly differant look and sheet size. The Range is A1..S58 the range that
it creates with the tab is A1..V63. It also adds back row & column headers,
which I don't want. It has some potential but it is ackward.

1. I like your simple approach but any idea on the problems?
2. Is my method possible?
 
T

Tom Ogilvy

Sure you can set your own zoom level. You have to use the windows API to
get the screen resolution. You will then have to experiment with your
workbook on different screens to get the proper scale factor to set it to.

Here are some methods.

==============
Posted by Laurent Longre, Programming 06/10/99

Declare Function GetDeviceCaps Lib "Gdi32" (ByVal hdc As Long, _
ByVal nIndex As Long) As Long
Declare Function GetDC Lib "User32" (ByVal hWnd As Long) As Long
Declare Function ReleaseDC Lib "User32" (ByVal hWnd As Long, _
ByVal hdc As Long) As Long

Sub Test()
Dim DC As Long
DC = GetDC(0)
MsgBox "Resolution : " & GetDeviceCaps(DC, 8) _
& " * " & GetDeviceCaps(DC, 10) & " pixels"
ReleaseDC 0, DC
End Sub
==================

Option Explicit

Private Declare Function GetSystemMetrics _
Lib "user32" (ByVal nIndex As _
Long) As Long

Private Const SM_CXSCREEN = 0
Private Const SM_CYSCREEN = 1

Public Function GSR() As String
GSR = CStr(GetSystemMetrics(SM_CXSCREEN)) _
& "x" & CStr(GetSystemMetrics _
(SM_CYSCREEN))
End Function
===================

Declare Function GetSystemMetrics32 Lib "user32" Alias "GetSystemMetrics"
(ByVal nIndex As Long) As Long


Function DisplayVideoResolution() As String
DisplayVideoResolution = GetSystemMetrics32(0) & " x " &
GetSystemMetrics32(1)
End Function

Sub a()
If DisplayVideoResolution = "1024 x 768" Then Zoom = 100
If DisplayVideoResolution = "800 x 600" Then Zoom = 80
If DisplayVideoResolution = "640 x 480" Then Zoom = 50

' now use the Zoom variable.
.. . .
End Sub

Place each in a general module at the top

============

Put this at the top of a general module:

'*****************************************************************
' DECLARATIONS SECTION
'*****************************************************************
Option Explicit
Type RECT
x1 As Long
y1 As Long
x2 As Long
y2 As Long
End Type
' NOTE: The following declare statements are case sensitive.
Declare Function GetDesktopWindow Lib "User32" () As Long
Declare Function GetWindowRect Lib "User32" _
(ByVal hWnd As Long, rectangle As RECT) As Long
'*****************************************************************
' FUNCTION: GetScreenResolution() ' ' PURPOSE:
' To determine the current screen size or resolution. '
' RETURN:
' The current screen resolution. Typically one of the following:
' 640 x 480 ' 800 x 600 ' 1024 x 768 '
'*****************************************************************
Function GetScreenResolution() As String
Dim R As RECT
Dim hWnd As Long
Dim RetVal As Long
hWnd = GetDesktopWindow()
RetVal = GetWindowRect(hWnd, R)
GetScreenResolution = (R.x2 - R.x1) & "x" & (R.y2 - R.y1)
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top