move the cursour to where you want in a protected sheet

Bodi

New Member
Joined
Nov 19, 2003
Messages
8
Hello there

How to force the movement of the cursor after the "enter" to follow a specified unprotected cells order in a protectd sheet. This movement will be a combination of vertical and horizontal to get you to the next specifies unprotected cell.

Thanks

Bodi :eek:
 
The following code gets the cursor position when the "getmouseposition" macro is called. The cursor returns to that position when "setmouseposition" is called. "leftclick" simulates a left mouse click. I would imagine that these can be combined to achieve your objective...perhaps save "getmouseposition" points in an array that meets your needs? Good luck. Dave
ps. I'd be interested to see your completed code if this is the route you take.
Code:
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" _
                                      (lpPoint As POINTAPI) As Long
Type POINTAPI
    x As Long
    y As Long
End Type
Public z As POINTAPI
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, _
ByVal dX As Long, _
ByVal dY As Long, _
ByVal dwData As Long, _
ByVal dwExtraInfo As Long)
Private Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)
' Flags used with mouse_event
Private Const MOUSEEVENTF_ABSOLUTE = &H8000& ' absolute move
Private Const MOUSEEVENTF_LEFTDOWN = &H2     ' left button down
Private Const MOUSEEVENTF_LEFTUP = &H4       ' left button up
Private Const MOUSEEVENTF_MIDDLEDOWN = &H20  ' middle button down
Private Const MOUSEEVENTF_MIDDLEUP = &H40    ' middle button up
Private Const MOUSEEVENTF_MOVE = &H1         ' mouse move
Private Const MOUSEEVENTF_RIGHTDOWN = &H8    ' right button down
Private Const MOUSEEVENTF_RIGHTUP = &H10     ' right button up
Private Const MOUSEEVENTF_WHEEL = &H800      ' wheel button rolled
Public Sub leftClick()
  ' Click the mouse, with delay to simulate human timing.
  mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
  Sleep 20
  mouse_event MOUSEEVENTF_LEFTUP, 0, xpt, 0, ypt
End Sub

Sub GetMousePosition()
    GetCursorPos z
End Sub
Sub SetMousePosition()
If x < 0 Or x > 1024 Or y < 0 Or y > 768 Then Exit Sub
    SetCursorPos z.x, z.y
End Sub
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,215,084
Messages
6,123,029
Members
449,092
Latest member
ikke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top