Could someone please suggest some VBA code to prevent a Word 2000 document (under Win2K) being saved with the same name if it has been changed? (I.e. forcing Save As a nother name).
Thanks.
Tony.
If you have an anti virus application running with auto-protection, it passibly don't allow to run this code (virus alert). It creates a new doc file, inserts a new module, a new sub that read-only opens the current file and closes oneself.
Insert these subs into a module:
'****************************************************************************************************************
Sub AutoOpen()
If Not Application.ActiveDocument.ReadOnly Then
Call MakeReadOnlyDoc(ActiveDocument.Name, ActiveDocument.Path & "\" & ActiveDocument.Name)
End If
End Sub
Sub MakeReadOnlyDoc(myName, openDocName)
Dim myDoc, myModule As Object
Set myDoc = Application.Documents.Add
Set myModule = myDoc.VBProject.VBComponents.Add(vbext_ct_StdModule)
myModule.CodeModule.AddFromString "Public Sub mySub()" & vbLf & _
"on error resume next" & vbLf & _
"'Documents(" & Chr(34) & myName & Chr(34) & ".Close False 'it not need.." & vbLf & _
"set MyDoc=activedocument" & vbLf & _
"Documents.Open " & Chr(34) & openDocName & Chr(34) & ", False, True, True" & vbLf & _
"myDoc.close False" & vbLf & _
"end sub"
Application.Run "mySub"
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.