Prevent "Save As" in Word 2010

canuck13

New Member
Joined
Oct 8, 2014
Messages
31
Hello all, I am looking to prevent my users from utilizing "Save As" for a word2010 document. In other words I want them to be able to save changes onthe master file that is accessible to the multiple people that need it but not be able to create an editable copy as inevitably they edit that file instead and call me saying the master file isn't working. I have done this in Excel for years with the Before Save event but do not use Word VBA a lot and based on my research it sounds like it is a bit more complicated. The following code is the only solution I was able to find on the internet. Things I have tried:


  1. It works fine when I try to save as on my computer butfor my users it doesn't seem to fire. This is true even when I remove my ErrorHandler code in Document_Open.
  2. The "criteria" I put in to make sure it doesn'timpact other files are met (i.e. path is correct and first three letters offile name are "CQC").
  3. The user had macros enabled for this file--other code ranas intended including putting a test msgbox directly before the code below inDocument_Open. IÂ’m out of ideas.
    Any ideas what I am doing wrong?

    Created Class Module CQCApplication with the followingcode:
Code:
Option Explicit
    Private WithEvents App As Application

Private Sub Class_Initialize()
    Set App = Word.Application
End Sub

Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI AsBoolean, Cancel As Boolean)
    'Prevents editable copies of document
    If SaveAsUI And _
        ActiveDocument.Path ="T:\Performance Improvement\PI Dashboard-Indicators\Reports" And _
        Left(ActiveDocument.Name,3) = "CQC" Then
    MsgBox "Copies of this file cannot be created. Please save changes in the original document."& _
    vbNewLine & vbNewLine& "An uneditable version of this report can be created by clicking" & _
    "the blue EXPORT buttonat the bottom of the screen.", , "Copy Cannot be Created"
        Cancel = True
    End If
End Sub

In “ThisDocument” for this file specifically (not “Normal”) I added:
Code:
Private Sub Document_Open()
    On Error GoTo ErrorHandler
    Set WdApp = NewCQCApplication
    Exit Sub
ErrorHandler:
    Call ErrorHandler
End Sub
There is additional unrelated code in Document_Open I can provide if anyone thinks it may be interfering but it is an if statement after this code that merely produces a messagebox if met. (Sorry about the code being "squished", not sure why its doing that.)
 
Last edited by a moderator:

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
(Sorry about the code being "squished", not sure why its doing that.)
That's a result of you messing with the fonts throughout your post. The standard forum fonts work just fine. Cleaned.

To prevent the use of File|Save As, all you need do is add the following code to the document or its template:
Code:
Sub FileSaveAs()
MsgBox "You're not supposed to do this", vbCritical
End Sub
Do note, though, there's nothing to prevent the miscreant making a copy via Windows Explorer...
 
Upvote 0
Thank you Paul and thanks for fixing the font... wasn't trying to mess with it but guess I did in pasting code!

Thank you also for the code. I am really hoping it is that simple and I'm still doing it wrong but I didn't get anything to fire just testing it out on a blank file. I put that exact code in ThisDocument for the file... no other code anywhere in my test file. I do not get a message box on Save As. Just for clarity's sake I am at home now so trying it on Word 2013 instead of 2010, but I shouldn't think that this would make a difference in this case.

I am ok with the Windows Explorer copy issue, most regular users will be accessing via a link and folder rights at least prevent them from putting the copy in the same folder. Appreciate your time and any further assistance you could provide.
 
Upvote 0
Thank you also for the code. I am really hoping it is that simple and I'm still doing it wrong but I didn't get anything to fire just testing it out on a blank file. I put that exact code in ThisDocument for the file... no other code anywhere in my test file. I do not get a message box on Save As.
With a new file, SaveAs is the only possibility. Whether you use Ctrl-S or File|Save, you'll get the SaveAs dialogue. The code only intercepts the user's attempt to save via File|SaveAs - which it does even on an unsaved file.
 
Upvote 0
Yes, I had accounted for that. I saved it as a .docm file "Test" (using save, not save as, but getting the save as dialogue since it was a new document at that time like you said). Then tried to save as "Test2" and was able to do so without any message box popping up.
 
Upvote 0

Forum statistics

Threads
1,215,636
Messages
6,125,961
Members
449,276
Latest member
surendra75

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top