0

I wrote this add-in in visual basic, and I need to toggle it on and off.

Imports Microsoft.Office.Interop.Excel

Public Class ThisAddIn

    Private Sub ThisAddIn_Startup() Handles Me.Startup

    End Sub

    Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown

    End Sub

    Sub Application_SheetChange(Sh As Object, Target As Range) Handles Application.SheetChange

        Target.Offset(0, 1).PrintOut(Copies:=1, Preview:=True)

    End Sub
End Class

I wrote a pseudo-code algorithm to solve this problem.

Imports Microsoft.Office.Interop.Excel

Public Class ThisAddIn

    int toggle = 0 'off

    Sub Press F1 key
        if (toggle == 1) 'if on turn off
            toggle = 0
        else
            toggle = 1 'else turn on

      End Sub


    Sub Application_SheetChange(Sh As Object, Target As Range) Handles Application.SheetChange

        if(toggle == 1)

            Target.Offset(0, 1).PrintOut(Copies:=1, Preview:=True)

    End Sub

End Class

I have the if statement and the variable working. I really just need help getting the KeyPress or KeyDown Function implemented.

I would like to use the F1 Key, so I think it needs to be a KeyDown Event.

If you have any suggestions it would be greatly appreciated.

user3609703
  • 11
  • 1
  • 1

1 Answers1

0

To catch keyboard events, you can use this code (it is in C#, but not too big for translation)

To skip default F1 action, use this code:

Application.OnKey("{F1}", "")
Community
  • 1
  • 1
Alex Butenko
  • 3,664
  • 3
  • 35
  • 54