Trapping or disabling Copy/Cut Paste

Add-in Express™ Support Service
That's what is more important than anything else

Trapping or disabling Copy/Cut Paste
 
Rob Blackin




Posts: 68
Joined: 2016-02-20
What is the best way to disable copy/cut/paste in word/ppt/excel and outlook

I trapped the ctrl C, ctrl V ctrl X but the context menu and ribbon menu I cant figure out. I need to disable if the user has no permission or capture the event and verify.

thanks for you help,

ROb
Posted 15 Nov, 2017 16:45:35 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Rob,

You use a Ribbon Command component to intercept or disable an action. This requires that you specify the IdMso of the control to intercept (or disable); see sections Intercepting built-in Ribbon controls and Disabling built-in Ribbon controls at https://www.add-in-express.com/docs/net-ribbon-components.php#intercepting-ribbon-controls. But still there are problems that you need to bypass. Please have a look at

https://www.add-in-express.com/forum/read.php?FID=5&TID=12302
https://www.add-in-express.com/forum/read.php?FID=5&TID=12832
https://www.add-in-express.com/forum/read.php?FID=5&TID=13077

The information on the pages above also applies to Excel 2016.


Andrei Smolin
Add-in Express Team Leader
Posted 16 Nov, 2017 03:29:29 Top
Rob Blackin




Posts: 68
Joined: 2016-02-20
Thanks, got it working.
Posted 16 Nov, 2017 22:52:14 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
You are welcome!


Andrei Smolin
Add-in Express Team Leader
Posted 17 Nov, 2017 02:19:43 Top
Rob Blackin




Posts: 68
Joined: 2016-02-20
Hi Andrei,

I have run into a little gotcha in the implementation. When the document is in Protected mode, the Ribbon Command setting seems to have no effect. I want to also turn off Copy/Cut but seems in Protected mode, I cannot. It is always there where a document not in protected mode works properly.

thanks,

Rob
Posted 19 Nov, 2017 16:52:50 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Rob,

I seem to have the same result. I'll try to get more information and let you know about my results tomorrow.


Andrei Smolin
Add-in Express Team Leader
Posted 20 Nov, 2017 09:12:20 Top
Rob Blackin




Posts: 68
Joined: 2016-02-20
Hi Andrei, any update?

thanks

ROb
Posted 22 Nov, 2017 08:35:18 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Rob,

I found a solution a minute ago:

private void adxRibbonButton2_OnClick(object sender, IRibbonControl control, bool pressed) {
    Excel.ProtectedViewWindow pvw = ExcelApp.ActiveProtectedViewWindow;
    Excel.Workbook parentWorkbook  = pvw.Workbook;
    Excel.Application app = parentWorkbook.Application;
    Office.CommandBars cBars = app.CommandBars;
    Office.CommandBar contextMenuBar = cBars["Cell"];
    if (contextMenuBar != null) {
        Office.CommandBarControl ctrl = contextMenuBar.FindControl(Type.Missing, 19);
        if (ctrl != null) {
            ctrl.Enabled = false;
            Marshal.ReleaseComObject(ctrl); ctrl = null;
        }
        Marshal.ReleaseComObject(contextMenuBar); contextMenuBar = null;
    }
    Marshal.ReleaseComObject(cBars); cBars = null;
    Marshal.ReleaseComObject(app); app = null;
    Marshal.ReleaseComObject(parentWorkbook); parentWorkbook = null;
    Marshal.ReleaseComObject(pvw); pvw = null;
}



Andrei Smolin
Add-in Express Team Leader
Posted 22 Nov, 2017 08:48:52 Top
Rob Blackin




Posts: 68
Joined: 2016-02-20
Wow, I never would have figured that out. I will try it out.

Will this method work for Word and PPT too?


Also, side question, I am sure that we are not ReleasingObjects properly. Do you provide and consulting services to review code and ensure we are releasing properly so we dont have glitchy issues?

thanks,

Rob
Posted 22 Nov, 2017 09:10:32 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Hello Rob,

Rob Blackin writes:
Will this method work for Word and PPT too?


I can't make a similar approach work with PowerPoint. I'll spend some more time on this issue and let you know about my result.

Rob Blackin writes:
Do you provide and consulting services to review code and ensure we are releasing properly so we dont have glitchy issues?


I know an only straightforward way I: you upgrade to Premium and we perform the code review as part of services the Premium subscription provides.


Andrei Smolin
Add-in Express Team Leader
Posted 23 Nov, 2017 06:11:52 Top