Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to get the screen resolution in VBA

In native VB I get the screen resolution with
Screen.Width \ Screen.TwipsPerPixelX
Screen.Height \ Screen.TwipsPerPixelY

And if I'd like to position a window at the right bottom corner I can
calculate the position with
Screen.Width - Me.Width
Screen.Height - Me.Height

However, 'Screen' doesn't exist in VBA (e.g. Excel).
Does anyone know how I can do it in VBA?

Stefan

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 182
Default How to get the screen resolution in VBA

Hi,

I use this way:
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 ScreenHeight() As Long
ScreenHeight = GetSystemMetrics(SM_CYSCREEN)
End Function

Public Function ScreenWidth() As Long
ScreenWidth = GetSystemMetrics(SM_CXSCREEN)
End Function

I've modified from original by Stephen Bullen
--
Regards,

Halim



"Stefan Mueller" wrote:

In native VB I get the screen resolution with
Screen.Width \ Screen.TwipsPerPixelX
Screen.Height \ Screen.TwipsPerPixelY

And if I'd like to position a window at the right bottom corner I can
calculate the position with
Screen.Width - Me.Width
Screen.Height - Me.Height

However, 'Screen' doesn't exist in VBA (e.g. Excel).
Does anyone know how I can do it in VBA?

Stefan


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default How to get the screen resolution in VBA

Here is a way to get the dimensions of the screen's physical "work" area
(the part left over after accounting for the Windows TaskBar and any other
taskbars that might be on the screen)...

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function MoveWindow Lib "user32" _
(ByVal hWnd As Long, _
ByVal X As Long, _
ByVal Y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long) As Long

Private Const SPI_GETWORKAREA = 48

Private Declare Function SystemParametersInfo Lib "user32" _
Alias "SystemParametersInfoA" _
(ByVal uAction As Long, _
ByVal uParam As Long, _
lpvParam As Any, _
ByVal fuWinIni As Long) As Long

Sub GetWorkArea(waLeft As Integer, waTop As Integer, _
waWidth As Integer, waHeight As Integer)
Dim rcWork As RECT
SystemParametersInfo SPI_GETWORKAREA, 0, rcWork, 0
With rcWork
waLeft = .Left
waTop = .Top
waWidth = (.Right - .Left)
waHeight = (.Bottom - .Top)
End With
End Sub

Your can call the above subroutine using this sample code...

Private Sub CommandButton1_Click()
Dim L As Integer
Dim T As Integer
Dim W As Integer
Dim H As Integer
GetWorkArea L, T, W, H
MsgBox "Left: " & L & vbCrLf & _
"Top: " & T & vbCrLf & _
"Width: " & W & vbCrLf & _
"Height: " & H
End Sub

Rick


"Halim" wrote in message
...
Hi,

I use this way:
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 ScreenHeight() As Long
ScreenHeight = GetSystemMetrics(SM_CYSCREEN)
End Function

Public Function ScreenWidth() As Long
ScreenWidth = GetSystemMetrics(SM_CXSCREEN)
End Function

I've modified from original by Stephen Bullen
--
Regards,

Halim



"Stefan Mueller" wrote:

In native VB I get the screen resolution with
Screen.Width \ Screen.TwipsPerPixelX
Screen.Height \ Screen.TwipsPerPixelY

And if I'd like to position a window at the right bottom corner I can
calculate the position with
Screen.Width - Me.Width
Screen.Height - Me.Height

However, 'Screen' doesn't exist in VBA (e.g. Excel).
Does anyone know how I can do it in VBA?

Stefan



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Screen Resolution Jason Zischke Excel Programming 1 February 20th 06 07:17 AM
Screen Resolution Jason Zischke Excel Programming 2 February 15th 06 05:36 AM
Can't get screen resolution StevenS Excel Programming 3 November 12th 05 01:01 PM
Screen Resolution Ronbo Excel Programming 2 January 17th 05 08:45 PM
Screen Resolution Sheldon Excel Programming 1 November 2nd 04 05:52 PM


All times are GMT +1. The time now is 09:27 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"