Disable Office Print, Save Command Button for Word, Excel and PowerPoint

> Edraw Tip > Disable Office Print, Save Command Button for Word, Excel and PowerPoint
author
Posted by James Freeman |
Edraw Office Viewer Component allows developers to disable office save, open, new, print button in Word, Excel or PowerPoint program.

Disable Office Ribbon Button

Edraw Office Viewer Components can disable the office main button and protects the opened document from modification. Only call the DisableFileCommand method in the BeforeDocumentOpen event and set the different enumerates.

Download Office Viewer Component and View Sample Projects
boolean DisableFileCommand([in] WdUIType UIType, [in] boolean Disable);
UIType: The enum type need to disable in the UI. WdUIType.
Disable: True to disable the command button or menu item.


enum WdUIType
{
wdUIDisalbeOfficeButton = 0x00000001,
wdUIDisalbeNew = 0x00000002,
wdUIDisalbeOpen = 0x00000004,
wdUIDisalbeUpgradeDocument = 0x00000008,
wdUIDisalbeSave = 0x00000010,
wdUIDisalbeSaveAs = 0x00000020,
wdUIDisalbeSendAsAttachment = 0x00000040,
wdUIDisalbeClose = 0x00000100,
wdUIDisalbePrint = 0x00000200,
wdUIDisalbePrintQuick = 0x00000400,
wdUIDisalbePrintPreview = 0x00000800,
wdUIDisalbeSaveAsMenu = 0x00001000,
wdUIDisalbePrepareMenu = 0x00002000,
wdUIDisalbePermissionRestrictMenu = 0x00004000,
wdUIDisalbeSendMenu = 0x00008000,
wdUIDisalbePublishMenu = 0x00010000,
wdUIDisalbeServerTasksMenu = 0x00020000,
wdUIDisalbeCopyButton = 0x00040000,
wdUIDisalbeCutButton = 0x00080000,
wdUIHideMenuHome = 0x01000000,
wdUIHideMenuInsert = 0x02000000,
wdUIHideMenuPageLayout = 0x04000000,
wdUIHideMenuReferences = 0x08000000,
wdUIHideMenuMailings = 0x10000000,
wdUIHideMenuReview = 0x20000000,
wdUIHideMenuView = 0x40000000,
wdUIHideMenuDeveloper = 0x80000000,
wdUIHideMenuAddIns = 0x00100000,
wdUIHideMenuFormat = 0x00200000,
wdUIHideMenuEdit = 0x00400000,
wdUIHideMenuTool = 0x00800000,
}WdUIType;

Note: The component disabled the Office menu, New button and Open button in default.
DWORD dwDisableCommand = wdUIDisalbeOfficeButton | wdUIDisalbeNew| wdUIDisalbeOpen;
The function needs to be set in the BeforeDocumentOpened event. If you want to enable the three buttons, follow the samples.

The following VBScript shows how to enable the office main menu, new button and open button.

Sub DocumentOpenedEvent ()
Edword.DisableFileCommand 1 , false 'wdUIDisalbeOfficeButton
Edword.DisableFileCommand 2 , false 'wdUIDisalbeNew
Edword.DisableFileCommand 4 , false 'wdUIDisalbeOpen
End Sub
SCRIPT FOR=OA1 EVENT= DocumentOpened ()
DocumentOpenedEvent()
SCRIPT

Disable SaveAs and Save button

Sub DocumentOpenedEvent ()
Edword.DisableFileCommand 16 , true 'wdUIDisalbeSave
Edword.DisableFileCommand 32 , true 'wdUIDisalbeSaveAs
End Sub
SCRIPT FOR=OA1 EVENT= DocumentOpened ()
DocumentOpenedEvent()
SCRIPT

Disable Office Print, Save Command Button

Disable Ribbon Main Button

You can disable the whole ribbon main button in the MS Office Ribbon. Just call the document.OA1.DisableFileCommand(1, true) in the NofityCtrlReady event.

Disable Ribbon main button

If you want to hide the whole ribbon, you need set the Toolbar property as false.

Disable the mailing menu and reference menu in the Ribbon interface

Some developers would like to hide the special menu bar at the Ribbon interface. The Edraw Office Viewer Component can realize the target.

Disable office ribbon menu

Add the follow code at the NotifyCtrlReady event.

document.OA1.DisableFileCommand(4194304, true);//wdUIHideMenuPageLayout = 0x00400000,
document.OA1.DisableFileCommand(8388608, true);//wdUIHideMenuReferences = 0x00800000,
document.OA1.DisableFileCommand(16777216, true);//wdUIHideMenuMailings = 0x01000000,
document.OA1.DisableFileCommand(65536, true);//wdUIDisalbePublishMenu = 0x00010000,

Disable the mailing menu and Reference menu

Disable the Office 2003 Command Button

For the office 2003, you can use the following method to show or hide the command bar.
boolean UpdateOffice2003ToolbarButton([in] long OfficeID, [in] boolean Visible, [in] boolean Enabled);

Disables or hides the office 2000, 2003 toolbar button.
OfficeID: The office MSO id for every button.
Visible: True to set the command button visible.
Enabled: True to enable the command button.

The function works only in the Office 2000/2003 version. The following VBScript shows how to hide the saveas and save button.

Sub DocumentOpenedEvent ()
Edword.UpdateOffice2003ToolbarButton 3 , false, false 'save button
Edword.UpdateOffice2003ToolbarButton 748 , false, false 'saveas button
End Sub
</SCRIPT FOR=OA1 EVENT= DocumentOpened ()>
DocumentOpenedEvent()
</SCRIPT>
Show or hide the office 2003 toolbar
boolean InvisibleOffice2003Toolbar([in] BSTR ToolbarName);
Disables or hides the office 2000, 2003 toolbar.
ToolbarName: The office 2000, 2003 commandbar name.
The following vb script shows how to hide the standard toolbar, web toolbar and formatting
toolbar.
Sub DocumentOpenedEvent ()
Edword.InvisibleOffice2003Toolbar "Standard"
Edword.InvisibleOffice2003Toolbar "Web"
Edword.InvisibleOffice2003Toolbar "Formatting"
End Sub
</SCRIPT FOR=OA1 EVENT= DocumentOpened ()>
DocumentOpenedEvent()
</SCRIPT>

download EdrawMind
main page

Get Started! You Will Love This Easy-To-Use Diagram Software

EdrawMax is an advanced all-in-one diagramming tool for creating professional flowcharts, org charts, mind maps, network diagrams, UML diagrams, floor plans, electrical diagrams, science illustrations, and more. Just try it, you will love it!