rsKRISH
rsKRISH

Reputation: 401

How to Disable Save, SaveAs button in MS-Word 2010/2013 using VBA

Using VBA, I want to disable (or hide) the Save and SaveAs button shown in the File menu in MS Word 2013 so that the user cannot click them.

I have tried disabling these buttons using this:

Word.CommandBars("File").Controls("&Save").Enabled = False
Word.CommandBars("File").Controls("&Save").Visible = False

But this has no effect. Is there any way I can disable these buttons?

Upvotes: 2

Views: 14619

Answers (2)

rsKRISH
rsKRISH

Reputation: 401

Since version 2007 the "menu controls" are no longer controlled via the CommandBars object model.So, to control menu items I have to define Ribbon XML that has to be either incorporated into the document, or be loaded as part of an Add-in.

To disable Save and SaveAs in Word 2010 I used this XML code :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
  <commands>
    <command idMso="FileSave" enabled="false" />
    <command idMso="FileSaveAsMenu" enabled="false" />
    <command idMso="FileSaveAsWordDocx" enabled="false" />
    <command idMso="FileSaveAsWordDotx" enabled="false" />
    <command idMso="FileSaveAs" enabled="false" />
    <command idMso="FileSaveAsWord97_2003" enabled="false" />
    <command idMso="FileSaveAsPdfOrXps" enabled="false" />
    <command idMso="FileSaveAsOtherFormats" enabled="false" />
    <command idMso="FileSaveToDocumentManagementServer" enabled="false" />
    <command idMso="SaveSelectionToQuickPartGallery" enabled="false" />
    <command idMso="FrameSaveCurrentAs" enabled="false" />
    <command idMso="FileSaveAsWordOpenDocumentText" enabled="false" />
  </commands>
</customUI>

I used Custom UI Editor for executing and testing this code. This link provides a nice training of how to use Custom UI Editor.

Thanks

Upvotes: 3

Santosh
Santosh

Reputation: 12353

You can use Workbook_BeforeSave event.

http://msdn.microsoft.com/en-us/library/office/ff840057.aspx

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Cancel = True
End Sub

enter image description here

Upvotes: 2

Related Questions