'Cannot fully intercept or trap SaveAs Dialog

With the help of the web, I have been able to write some VBA to check content controls on a Word 2013 template document and use the content to create a filename when Save or Save As are chosen, using custom subroutines with the appropriate names:

Sub FileSave()
    If Left(ActiveDocument.Name, 4) = "PDR " Then
        ActiveDocument.Save
    Else
        Call FileSaveAs
    End If
End Sub

Sub FileSaveAs()
    ' too much to list, but in essence it 
    ' checks contents of content controls
    ' and if properly populated build a string to use as a filename 
    ' with the standard ActiveDocuments.SaveAs2 command
End Sub

The code works when using the keyboard methods of [Ctrl]+S/ pressing [F12], when using the standard Save button in the ribbon, and when using Save from the File menu.

However, if the user opts for the menu option and chooses File \ Save As... (i.e. the one that looks like this -

standard Word file menu choice

then it seems that the code in my FileSaveAs() routine gets bypassed and we get a normal Save As dialog box with the first couple of words from the document being suggested as the filename (i.e. standard Word behaviour).

How can I capture the menu method?

Alternatively, I did consider disabling "Save As..." from the File menu within a autonew() subroutine utilising CommandBars, but I can't get this to work. The sites I researched suggested that this ceased to be possible from Word 2010 onward.



Solution 1:[1]

I found that after Office 2007 you need to use a Custom UI editor to manipulate the XML of the file.

I then found that there was a change in some of the key words from Office 2013 onwards (when the "Office" button in the top left corner was replaced by the "File" menu). Not only does this link allow you to download the Custom UI Editor, but it gives the subtle details in the commands between Office 2010, 2013 and 2016: http://www.rondebruin.nl/win/s2/win005.htm

Whilst the page above refers to Excel, it appears to be common across Office as a whole. I used it to alter a Word 2013 file to successfully hide "Save As" from the File menu. Below is the relevant XML I employed to solve my particular issue:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
    <backstage>
        <tab idMso="TabSave" visible="false" />
    </backstage>
</customUI>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1