Make File Writable macro | CodeGuru

Make File Writable macro

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Jan 28, 1999
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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.

Sub MakeFileWriteable()
‘DESCRIPTION: Remove Read-Only File attribute from active document
‘ Author: V. Sauder
‘ Copyright: Hekimian Labs, Inc. 1999
    Dim doc
    Set doc = ActiveDocument
    Dim fname
    fname = doc.FullName
	if (doc.ReadOnly) then
		doc.ReadOnly = False
		msg = ToggleReadOnlyBit(fname)
		‘MsgBox msg
	end if
	Set doc = nothing
End Sub
const ReadOnly = 1
Function ToggleReadOnlyBit(filespec)
‘ 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.”
	Else
		ToggleReadOnlyBit = “ReadOnly bit is now cleared.”
	End If
End Function

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.