Ciao Maurizio,
Oppure, per spostare il cursore, anziché selezionare una cella (e ancora se
l'altezza delle righe e la larghezza delle colonne fossero costanti), in un
nuovo modulo standard, incollarci:
'=============>>
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
'--------------------->>
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
'--------------------->>
Public Sub Tester()
Dim rng As Range
With ActiveWindow.VisibleRange
Set rng = Cells(.Rows.Count \ 2 + 1, .Columns.Count \ 2 + 1)
End With
With TopLeftPoint(rng)
SetCursorPos .x, .y
End With
End Sub
'<<=============
Le funzione DPIfactors e TopLeftPoint sono di KeepITcool:
http://tinyurl.com/fd8vl
---
Regards,
Norman