#1
|
|||
|
|||
Disable Save and Save As
Hello,
I have created a form in Word. I want to write a VBA Code such that the user should not be able to save or do a saveas if they have not filled out certain data in the form. How do I stop the user from saving the document? Thanks |
#2
|
||||
|
||||
You can prevent a user from leaving a form field that has not been completed, though your bigger difficulty may be that you cannot force anyone to run the VBA necessary to do so.
The code required is reproduced at http://www.gmayor.com/formfieldmacros.htm
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
i need to stop the user from saving the word document; how do I disable that functionality?
|
#4
|
||||
|
||||
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 |
#5
|
|||
|
|||
When I add the procedures; it still saves the document. It does recognize the procedures. Do I need to call the procedures from another procedure?
Thanks for your help. |
#6
|
||||
|
||||
If your document has text form fields and those form fields are empty you will not be able to save the document, provided you allow the macros to run, and as I said you cannot force users to run the macros. See attached.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Macro to save as pdf with ability to choose save as folder | rvessio | Word VBA | 4 | 07-25-2016 12:37 PM |
Disable "do you also want to save changes to the document template?" harassalog. | wornways | Word | 30 | 06-04-2016 02:32 PM |
Disable "Save" & "Save As" & "Print" ribbon | Villalobos | Word VBA | 3 | 07-14-2014 11:37 PM |
When I try to save an existing word doc, save as pops up and will not save... | samanthab | Word | 3 | 01-19-2013 06:27 AM |
Word ask to save template whenever i save a derived document | jorbjo | Word | 3 | 10-04-2012 10:52 AM |