开发者

Disable Ctrl+V paste option from Excel template in VSTO

开发者 https://www.devze.com 2023-02-08 00:56 出处:网络
I am working on an Excel template + VSTO application. I have assigned various custom validations and formats for various cells.

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开发者_JS百科 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.

Application.OnKey("^v", "");

If you would like to restore Ctrl+V, call the following:

Application.OnKey("^v", Type.Missing);

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号