Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-18-2015, 10:28 PM
Sgur Sgur is offline Disable Save and Save As Windows XP Disable Save and Save As Office 2010 64bit
Novice
Disable Save and Save As
 
Join Date: Jan 2015
Posts: 3
Sgur is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 01-18-2015, 11:03 PM
gmayor's Avatar
gmayor gmayor is offline Disable Save and Save As Windows 7 64bit Disable Save and Save As Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 of
Default

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
Reply With Quote
  #3  
Old 01-19-2015, 12:03 AM
Sgur Sgur is offline Disable Save and Save As Windows XP Disable Save and Save As Office 2010 64bit
Novice
Disable Save and Save As
 
Join Date: Jan 2015
Posts: 3
Sgur is on a distinguished road
Default

i need to stop the user from saving the word document; how do I disable that functionality?
Reply With Quote
  #4  
Old 01-19-2015, 12:23 AM
gmayor's Avatar
gmayor gmayor is offline Disable Save and Save As Windows 7 64bit Disable Save and Save As Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 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
  #5  
Old 01-19-2015, 03:13 AM
Sgur Sgur is offline Disable Save and Save As Windows XP Disable Save and Save As Office 2010 64bit
Novice
Disable Save and Save As
 
Join Date: Jan 2015
Posts: 3
Sgur is on a distinguished road
Default

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.
Reply With Quote
  #6  
Old 01-19-2015, 03:38 AM
gmayor's Avatar
gmayor gmayor is offline Disable Save and Save As Windows 7 64bit Disable Save and Save As Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 of
Default

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.
Attached Files
File Type: docm Form Test.docm (27.5 KB, 24 views)
__________________
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
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable Save and Save As 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
Disable Save and Save As 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

Other Forums: Access Forums

All times are GMT -7. The time now is 12:21 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft