Thread: [Solved] Disable Save and Save As
View Single Post
 
Old 01-19-2015, 12:23 AM
gmayor's Avatar
gmayor gmayor is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The same issue with respect to macros applies, however you can intercept the filesave and filesaveas functions in the document, by adding the following code to the document and save it from the vba editor (because you won't be able to save it from the document itself) as a macro enabled document.

It is not possible to determine whether a check box should be checked or not, nor is it possible to check that the selection in a dropdown form field is correct (unless you have default text which is not a valid result).

Code:
Option Explicit

Sub FileSaveAs()
    On Error Resume Next
    If DataCheck = True Then GoTo lbl_Exit
    Dialogs(wdDialogFileSaveAs).Show
lbl_Exit:
    Exit Sub
End Sub

Sub FileSave()
    On Error Resume Next
    If DataCheck = True Then GoTo lbl_Exit
    ActiveDocument.Save
lbl_Exit:
    Exit Sub
End Sub

Private Function DataCheck() As Boolean
Dim oFF As FormField
    For Each oFF In ActiveDocument.FormFields
        If oFF.Type = wdFieldFormTextInput Then
            If oFF.Result = "" Then
                DataCheck = True
                MsgBox "You must complete then form before you can save it!"
                oFF.Select
                Exit For
            End If
        End If
    Next oFF
lbl_Exit:
    Exit Function
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote