Is there any way to change Excel cursor for specific Workbook? Can't find any solution for this.
My Workbook is locked for editing cells, only certain cells are available and I want to replace this Excel cursor:
By pointer:
I have went through this but don't understand is it possible to implement it in Workbook? https://docs.microsoft.com/en-us/office/vba/api/excel.application.cursor
Private Sub Workbook_Open()
Application.Cursor = xlDefault
End Sub
In ThisWorkbook
code module, you could do something like this. The idea here is that we capture the initial cursor style when the workbook is opened (the Workbook_Open
event calls on changeCursor
which stores the current cursor style in the cursor
variable. Then we add some more event handlers so that when the workbook loses focus ( Workbook_Deactivate
) and before it closes ( Workbook_BeforeClose
) we restore that cursor to its previous style via the resetCursor
method. There may be additional edge cases that I haven't considered, but this is the general idea you'll need to implement.
Option Explicit
Private cursor As Long
Private Sub Workbook_Activate()
changeCursor
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
resetCursor
End Sub
Private Sub Workbook_Deactivate()
resetCursor
End Sub
Private Sub Workbook_Open()
changeCursor
End Sub
Private Sub changeCursor()
cursor = Application.cursor
Application.cursor = xlNorthwestArrow
End Sub
Private Sub resetCursor()
On Error Resume Next
Application.cursor = cursor
If Err.Number <> 0 Then
Application.cursor = xlDefault
End If
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.