Discussione:
Muovere il cursore by VBA
(troppo vecchio per rispondere)
Maurizio
2006-03-14 09:52:44 UTC
Permalink
E' possibile muovere tramite vba il cursore al centro e/o piè di pagina?

Grazie.
Franz Verga
2006-03-14 10:11:07 UTC
Permalink
Post by Maurizio
E' possibile muovere tramite vba il cursore al centro e/o piè di pagina?
Ciao Maurizio.
Se per cursore intendi la cella selezionata, basta fare:

Range("E28").Select

per selezionare una cella al centro della pagina, oppure:


Range("E56").Select

Questi range, ovviamente, dipendono dalla stampante installata, per cui
dovresti fare delle prove...
--
Spero d'esserti stato d'aiuto.

Ciao

Franz Verga
Maurizio
2006-03-14 10:31:40 UTC
Permalink
Franz intendo proprio il cursore (freccia-clessidra-croce).
Post by Franz Verga
Post by Maurizio
E' possibile muovere tramite vba il cursore al centro e/o piè di pagina?
Ciao Maurizio.
Range("E28").Select
Range("E56").Select
Questi range, ovviamente, dipendono dalla stampante installata, per cui
dovresti fare delle prove...
--
Spero d'esserti stato d'aiuto.
Ciao
Franz Verga
Franz Verga
2006-03-14 10:38:42 UTC
Permalink
Post by Maurizio
Franz intendo proprio il cursore (freccia-clessidra-croce).
Allora non so proprio come aiutarti, per queste cose così raffinate lascio
il campo a Mauro, Norman, Bruno e gli altri signori del VBA... :-(
--
Ciao

Franz Verga
Tiziano Marmiroli
2006-03-14 11:00:25 UTC
Permalink
Post by Maurizio
Franz intendo proprio il cursore (freccia-clessidra-croce).
Intendi proprio il 'puntatore'! :-)
Ne abbiamo già discusso in passato, credo che l'unica possibilità sia
ricorrere alle API di Windows. Se non interviene nessun'altro dopo ti do
qualche dettaglio in più.
--
Tiziano Marmiroli
Microsoft MVP - Office System
Norman Jones
2006-03-14 11:50:11 UTC
Permalink
Ciao Maurizio,
Post by Maurizio
E' possibile muovere tramite vba il cursore al centro e/o piè di pagina?
Se l'altezza delle righe e la larghezza delle colonne fossero costanti,
protresti provare:

'=============>>
Public Sub Tester()

With ActiveWindow.VisibleRange
Cells(.Rows.Count \ 2 + 1, .Columns.Count \ 2 + 1).Select
End With

End Sub
'<<=============


---
Regards,
Norman
Norman Jones
2006-03-14 12:50:20 UTC
Permalink
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
Maurizio
2006-03-14 13:45:33 UTC
Permalink
PERFECT!
Post by Norman Jones
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
'=============>>
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
'<<=============
http://tinyurl.com/fd8vl
---
Regards,
Norman
Loading...