What am I missing?

K

keithb

What am I missing? This code is in the "ThisWorkbook" Module; however it
does not execute ShiftLeft and ShiftRight when the designated keys are
pressed.

Private Sub App_WorkbookOpen(ByVal Wb As Workbook)
Application.OnKey "%{LEFT}", "ShiftLeft"
Application.OnKey "%{RIGHT}", "ShiftRight"
End Sub


Sub ShiftLeft()
With Selection
If (.IndentLevel > 0) Then
.InsertIndent -1
Else
Beep
End If
End With
End Sub

Sub ShiftRight()
With Selection
If (.IndentLevel < 15) Then
.InsertIndent 1
Else
Beep
End If
End With
End Sub
 
J

Jim Thomlinson

I am assuming that this is a regular workbook and not an addin? Do you have a
class instantiated to catch events. If not then in ThisWorkbook you want

Private Sub Workbook_Open()
Application.OnKey "%{LEFT}", "ShiftLeft"
Application.OnKey "%{RIGHT}", "ShiftRight"
End Sub
 
S

SKRS

hey thr,

this assignment in workbook_open is havin no effect.

Private Sub Workbook_Open()
MsgBox "open"
Application.OnKey "{~}", "EnterKey"
End Sub
Sub EnterKey()
MsgBox "enter key"
Call ActiveCell.Offset(ActiveSheet.Target.Row + 1,
ActiveSheet.Target.Column)
End Sub

in the above code, enterkey is not being invoked. where should the
application.onKey assignment be done.

appreciate your inputs.

thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top