We use MKS to archive our code and always set the local copy to read-only
when it is locked. Sometimes either another person has a file locked that I
need to modify or I want to simply try out a change without modifying the
project. For that I need to simply remove the read-only attribute from my
file. Using a DOS box or Explorer is time consuming at best. Since I had
used a macro in Borland for this purpose, I was spoiled and needed one in
Visual Studio. Here is a simple one that does the trick.
'DESCRIPTION: Remove Read-Only File attribute from active document
' Author: V. Sauder
' Copyright: Hekimian Labs, Inc. 1999
Set doc = ActiveDocument
fname = doc.FullName
if (doc.ReadOnly) then
doc.ReadOnly = False
msg = ToggleReadOnlyBit(fname)
Set doc = nothing
const ReadOnly = 1
' Copyright Microsoft. VBscript example code slighty modified.
Dim oFS, oFile
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oFile = oFS.GetFile(filespec)
oFile.attributes = oFile.attributes xor ReadOnly
If oFile.attributes and ReadOnly Then
ToggleReadOnlyBit = "ReadOnly bit is now set."
ToggleReadOnlyBit = "ReadOnly bit is now cleared."