Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default X and Y Screen Coordinates of a Range !!!

Hi all,

Is there any way I can determine the x and y screen coordinates of a given
Worksheet Range ?

Something similar to the 'RangeFromPoint' property of the Window Object
but the other way around .I would call it ' PointFromRange ' !!

I can't seem to get an answer to this anywhere.

Any suggestions would be much appreciated .

Regards.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default X and Y Screen Coordinates of a Range !!!


You could hardcode for 96 dpi settings,
better to read it form the system:

Option Explicit

Private Type POINTAPI
x As Long
y As Long
End Type

Private Declare Function SetCursorPos Lib "user32.dll" ( _
ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" ( _
ByVal hDC As Long, ByVal nIndex As Long) As Long
Private Declare Function GetDC Lib "user32" ( _
ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" ( _
ByVal hwnd As Long, ByVal hDC As Long) As Long

Private Function DPIfactors()
Static sdArr(1 To 2) As Double
Dim hDC&
If sdArr(1) = 0 Then
hDC = GetDC(0)
sdArr(1) = GetDeviceCaps(hDC, 88) / 72 'Horz
sdArr(2) = GetDeviceCaps(hDC, 90) / 72 'Vert
ReleaseDC 0, hDC
End If
DPIfactors = sdArr
End Function

Sub Test()
With TopLeftPoint(Selection)
SetCursorPos .x, .y
End With
End Sub

Function TopLeftPoint(rng As Range) As POINTAPI
With TopLeftPoint
.x = ActiveWindow.PointsToScreenPixelsX(rng.Left * DPIfactors(1))
.y = ActiveWindow.PointsToScreenPixelsY(rng.Top * DPIfactors(2))
End With
End Function




--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


RAFAAJ2000 wrote :

Hi all,

Is there any way I can determine the x and y screen coordinates of a
given Worksheet Range ?

Something similar to the 'RangeFromPoint' property of the Window
Object but the other way around .I would call it ' PointFromRange ' !!

I can't seem to get an answer to this anywhere.

Any suggestions would be much appreciated .

Regards.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default X and Y Screen Coordinates of a Range !!!


note that you need to check that the range intersects with the
activewindow.visiblerange else you should set the scrollrow and
scrollcolumn first.

--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


keepITcool wrote :



Sub Test()
With TopLeftPoint(Selection)
SetCursorPos .x, .y
End With
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default X and Y Screen Coordinates of a Range !!!

Really impressed !!

Although I don't really understand the use of the 'GetDeviceCaps' or where
the '88' & '90' constantes came from but it works !

I looked up this API function but found it somewhat confusing :(


I am impressed with the level of knowledge on this Forum with regards to Win
API and how it can be succesfully applied to the Excel environment\VBA.

All the API learning material that I have come accross ( Including the most
acclaimed Dan Appleman's textbook ) seem to me rather shallow, abstract or
far too advanced.

Deos anyone know of more step by step VB API learnig material(s) with
plenty of real world working examples for beginners ?

Any suggestions would much appreciated.

Jaafar.
Thanks very much.








"keepITcool" wrote:


You could hardcode for 96 dpi settings,
better to read it form the system:

Option Explicit

Private Type POINTAPI
x As Long
y As Long
End Type

Private Declare Function SetCursorPos Lib "user32.dll" ( _
ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" ( _
ByVal hDC As Long, ByVal nIndex As Long) As Long
Private Declare Function GetDC Lib "user32" ( _
ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" ( _
ByVal hwnd As Long, ByVal hDC As Long) As Long

Private Function DPIfactors()
Static sdArr(1 To 2) As Double
Dim hDC&
If sdArr(1) = 0 Then
hDC = GetDC(0)
sdArr(1) = GetDeviceCaps(hDC, 88) / 72 'Horz
sdArr(2) = GetDeviceCaps(hDC, 90) / 72 'Vert
ReleaseDC 0, hDC
End If
DPIfactors = sdArr
End Function

Sub Test()
With TopLeftPoint(Selection)
SetCursorPos .x, .y
End With
End Sub

Function TopLeftPoint(rng As Range) As POINTAPI
With TopLeftPoint
.x = ActiveWindow.PointsToScreenPixelsX(rng.Left * DPIfactors(1))
.y = ActiveWindow.PointsToScreenPixelsY(rng.Top * DPIfactors(2))
End With
End Function




--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


RAFAAJ2000 wrote :

Hi all,

Is there any way I can determine the x and y screen coordinates of a
given Worksheet Range ?

Something similar to the 'RangeFromPoint' property of the Window
Object but the other way around .I would call it ' PointFromRange ' !!

I can't seem to get an answer to this anywhere.

Any suggestions would be much appreciated .

Regards.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default X and Y Screen Coordinates of a Range !!!

get yourself 2 tools:

ApiViewer 2004 (syntax w/copy paste)
make sure you install/load the VBE addin)
http://www.activevb.de/rubriken/apiv...viewereng.html

ApiGuide (reference and examples)
http://www.mentalis.org/agnet/apiguide.shtml


happy learning!

--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


RAFAAJ2000 wrote :

Really impressed !!

Although I don't really understand the use of the 'GetDeviceCaps'
or where the '88' & '90' constantes came from but it works !

I looked up this API function but found it somewhat confusing :(


I am impressed with the level of knowledge on this Forum with regards
to Win API and how it can be succesfully applied to the Excel
environment\VBA.

All the API learning material that I have come accross ( Including
the most acclaimed Dan Appleman's textbook ) seem to me rather
shallow, abstract or far too advanced.

Deos anyone know of more step by step VB API learnig material(s)
with plenty of real world working examples for beginners ?

Any suggestions would much appreciated.

Jaafar.
Thanks very much.








"keepITcool" wrote:


You could hardcode for 96 dpi settings,
better to read it form the system:

Option Explicit

Private Type POINTAPI
x As Long
y As Long
End Type

Private Declare Function SetCursorPos Lib "user32.dll" ( _
ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" ( _
ByVal hDC As Long, ByVal nIndex As Long) As Long
Private Declare Function GetDC Lib "user32" ( _
ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" ( _
ByVal hwnd As Long, ByVal hDC As Long) As Long

Private Function DPIfactors()
Static sdArr(1 To 2) As Double
Dim hDC&
If sdArr(1) = 0 Then
hDC = GetDC(0)
sdArr(1) = GetDeviceCaps(hDC, 88) / 72 'Horz
sdArr(2) = GetDeviceCaps(hDC, 90) / 72 'Vert
ReleaseDC 0, hDC
End If
DPIfactors = sdArr
End Function

Sub Test()
With TopLeftPoint(Selection)
SetCursorPos .x, .y
End With
End Sub

Function TopLeftPoint(rng As Range) As POINTAPI
With TopLeftPoint
.x = ActiveWindow.PointsToScreenPixelsX(rng.Left *
DPIfactors(1)) .y = ActiveWindow.PointsToScreenPixelsY(rng.Top
* DPIfactors(2)) End With
End Function




--
keepITcool
www.XLsupport.com | keepITcool chello nl | amsterdam



RAFAAJ2000 wrote :

Hi all,

Is there any way I can determine the x and y screen coordinates
of a given Worksheet Range ?

Something similar to the 'RangeFromPoint' property of the Window
Object but the other way around .I would call it ' PointFromRange
' !!

I can't seem to get an answer to this anywhere.

Any suggestions would be much appreciated .

Regards.




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default X and Y Screen Coordinates of a Range !!!

Hi again,

The code doesn't work as expected when I change the Sheet Zooming !

In other words, the code works only if the Zoom is set to 100 otherwise it
gives erroneous results !

Any Idea how this can be fixed so it always works regardeless of the
current Sheet Zoom ?

Regards.



"keepITcool" wrote:

get yourself 2 tools:

ApiViewer 2004 (syntax w/copy paste)
make sure you install/load the VBE addin)
http://www.activevb.de/rubriken/apiv...viewereng.html

ApiGuide (reference and examples)
http://www.mentalis.org/agnet/apiguide.shtml


happy learning!

--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


RAFAAJ2000 wrote :

Really impressed !!

Although I don't really understand the use of the 'GetDeviceCaps'
or where the '88' & '90' constantes came from but it works !

I looked up this API function but found it somewhat confusing :(


I am impressed with the level of knowledge on this Forum with regards
to Win API and how it can be succesfully applied to the Excel
environment\VBA.

All the API learning material that I have come accross ( Including
the most acclaimed Dan Appleman's textbook ) seem to me rather
shallow, abstract or far too advanced.

Deos anyone know of more step by step VB API learnig material(s)
with plenty of real world working examples for beginners ?

Any suggestions would much appreciated.

Jaafar.
Thanks very much.








"keepITcool" wrote:


You could hardcode for 96 dpi settings,
better to read it form the system:

Option Explicit

Private Type POINTAPI
x As Long
y As Long
End Type

Private Declare Function SetCursorPos Lib "user32.dll" ( _
ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" ( _
ByVal hDC As Long, ByVal nIndex As Long) As Long
Private Declare Function GetDC Lib "user32" ( _
ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" ( _
ByVal hwnd As Long, ByVal hDC As Long) As Long

Private Function DPIfactors()
Static sdArr(1 To 2) As Double
Dim hDC&
If sdArr(1) = 0 Then
hDC = GetDC(0)
sdArr(1) = GetDeviceCaps(hDC, 88) / 72 'Horz
sdArr(2) = GetDeviceCaps(hDC, 90) / 72 'Vert
ReleaseDC 0, hDC
End If
DPIfactors = sdArr
End Function

Sub Test()
With TopLeftPoint(Selection)
SetCursorPos .x, .y
End With
End Sub

Function TopLeftPoint(rng As Range) As POINTAPI
With TopLeftPoint
.x = ActiveWindow.PointsToScreenPixelsX(rng.Left *
DPIfactors(1)) .y = ActiveWindow.PointsToScreenPixelsY(rng.Top
* DPIfactors(2)) End With
End Function




--
keepITcool
www.XLsupport.com | keepITcool chello nl | amsterdam


RAFAAJ2000 wrote :

Hi all,

Is there any way I can determine the x and y screen coordinates
of a given Worksheet Range ?

Something similar to the 'RangeFromPoint' property of the Window
Object but the other way around .I would call it ' PointFromRange
' !!

I can't seem to get an answer to this anywhere.

Any suggestions would be much appreciated .

Regards.


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default X and Y Screen Coordinates of a Range !!!

yep.
i agree didnt think about that...

wouldn't it be nice if:

you'd do some research and fiddling yourself
you'd find a solution
you'd give me the refined code.

... would fit well with "happy learning"
<g


--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


RAFAAJ2000 wrote :

Hi again,

The code doesn't work as expected when I change the Sheet Zooming !

In other words, the code works only if the Zoom is set to 100
otherwise it gives erroneous results !

Any Idea how this can be fixed so it always works regardeless of the
current Sheet Zoom ?

Regards.



"keepITcool" wrote:

get yourself 2 tools:

ApiViewer 2004 (syntax w/copy paste)
make sure you install/load the VBE addin)
http://www.activevb.de/rubriken/apiv...viewereng.html

ApiGuide (reference and examples)
http://www.mentalis.org/agnet/apiguide.shtml


happy learning!

--
keepITcool
www.XLsupport.com | keepITcool chello nl | amsterdam



RAFAAJ2000 wrote :

Really impressed !!

Although I don't really understand the use of the
'GetDeviceCaps' or where the '88' & '90' constantes came from
but it works !

I looked up this API function but found it somewhat confusing :(


I am impressed with the level of knowledge on this Forum with
regards to Win API and how it can be succesfully applied to the
Excel environment\VBA.

All the API learning material that I have come accross ( Including
the most acclaimed Dan Appleman's textbook ) seem to me rather
shallow, abstract or far too advanced.

Deos anyone know of more step by step VB API learnig material(s)
with plenty of real world working examples for beginners ?

Any suggestions would much appreciated.

Jaafar.
Thanks very much.








"keepITcool" wrote:


You could hardcode for 96 dpi settings,
better to read it form the system:

Option Explicit

Private Type POINTAPI
x As Long
y As Long
End Type

Private Declare Function SetCursorPos Lib "user32.dll" ( _
ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" ( _
ByVal hDC As Long, ByVal nIndex As Long) As Long
Private Declare Function GetDC Lib "user32" ( _
ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" ( _
ByVal hwnd As Long, ByVal hDC As Long) As Long

Private Function DPIfactors()
Static sdArr(1 To 2) As Double
Dim hDC&
If sdArr(1) = 0 Then
hDC = GetDC(0)
sdArr(1) = GetDeviceCaps(hDC, 88) / 72 'Horz
sdArr(2) = GetDeviceCaps(hDC, 90) / 72 'Vert
ReleaseDC 0, hDC
End If
DPIfactors = sdArr
End Function

Sub Test()
With TopLeftPoint(Selection)
SetCursorPos .x, .y
End With
End Sub

Function TopLeftPoint(rng As Range) As POINTAPI
With TopLeftPoint
.x = ActiveWindow.PointsToScreenPixelsX(rng.Left *
DPIfactors(1)) .y =
ActiveWindow.PointsToScreenPixelsY(rng.Top * DPIfactors(2))
End With End Function




--
keepITcool
www.XLsupport.com | keepITcool chello nl | amsterdam


RAFAAJ2000 wrote :

Hi all,

Is there any way I can determine the x and y screen
coordinates of a given Worksheet Range ?

Something similar to the 'RangeFromPoint' property of the
Window Object but the other way around .I would call it '
PointFromRange ' !!

I can't seem to get an answer to this anywhere.

Any suggestions would be much appreciated .

Regards.


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
Cell address nearest to screen coordinates Doug Glancy Excel Programming 0 August 25th 04 07:33 PM
Simple way to convert UTM ED50 coordinates to decimal coordinates? Dan[_38_] Excel Programming 8 July 11th 04 04:54 PM
getting coordinates of a range Kent Eilers Excel Programming 5 February 13th 04 02:09 PM
determining coordinates for screen placement of user form PatFinegan[_10_] Excel Programming 2 January 31st 04 09:03 PM
Screen Coordinates of a given cell in XL hglamy[_2_] Excel Programming 2 October 15th 03 02:03 PM


All times are GMT +1. The time now is 03:12 PM.

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

About Us

"It's about Microsoft Excel"