Pages

Friday, March 23, 2012

OnKey & SendKeys

OnKey & SendKeys

Sub Setup_OnKey()

    Application.OnKey "{pgdn}", "pgdn_sub"

    Application.OnKey "{pgUp}", "pgup_sub"

End Sub

 

Sub pgdn_sub()

On Error Resume Next

             If TypeName(ActiveSheet) = "Worksheet" _

            Then ActiveCell.Offset(1, 0).Activate

End Sub

 

Sub pgup_sub()

On Error Resume Next

    If TypeName(ActiveSheet) = "Worksheet" _

    Then ActiveCell.Offset(-1, 0).Activate

End Sub

Sub Cancel_OnKey()

Application.OnKey “{PgDn}”

Application.OnKey “{PgUp}”

End Sub

 

Private Sub Workbook_BeforeClose(Cancel As Boolean)

    Application.OnKey "{PgDn}"

    Application.OnKey "{PgUp}"

End Sub

 

Sub One()

    Dim Returnvalue

    Returnvalue = Shell("notepad.exe", vbNormalFocus)

    AppActivate Returnvalue  

    SendKeys "this shoud appear in a new NotePad", True

    SendKeys "~", True

    SendKeys "This is line one", True

    SendKeys "~", True

    SendKeys "This is line two", True

    SendKeys "%favba%s", True  

End Sub

 

Sub Two()

Dim Returnvalue, I

Returnvalue = Shell("calc.exe", 1)

AppActivate Returnvalue

    For I = 1 To 100

        SendKeys I & "{+}", True

    Next

    SendKeys "="

    SendKeys "%{F4}", True

End Sub

 

No comments:

Post a Comment