Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preventing overwriting with changed doc

Status
Not open for further replies.

tbalazs

IS-IT--Management
Dec 18, 2000
158
GB
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.
 
Dear Tony,

Couldn't you just change your document to a Template.
Which allways produces a new document.

Or you can write-protect your document on file level, so it coud not be changed at all.

HTH

regards Astrid
 
Kedves TBalazs,

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

i hope it suits for you
ide
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top