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:
In “ThisDocument” for this file specifically (not “Normal”) I added:
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.)
- 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.
- 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").
- 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
Last edited by a moderator: