I am working on an Excel template + VSTO application.
I have assigned various custom validations and formats for various cells.
But whenever I copy and paste something into the cell, these validations do not work (fails completely). Is there any way so I can disable (Ctrl + V) paste options from the Excel template?
I think it can be implemented in VBA macros.
But I’m not sure about it.
Have you tried using Application.OnKey? The following code should intercept Ctrl+V and effectively disable it. You should call it when your template opens.
If you would like to restore Ctrl+V, call the following:
In VBA you can put the name of a sub in the second parameter, which will be run when that key is pressed. I’m not sure how that works in VSTO.
Of course, the user could still use the cell menu or the edit menu to paste. Also, be aware that this will affect all workbooks running in the Excel instance.