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 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



Comments

  • I need to print a read-only file, not the only problem.

    Posted by Legacy on 12/17/2003 12:00am

    Originally posted by: Mark

    The real problem is this. I know how to remove the read only property, but the person I got the disc from has made it to where you can't print it or remove the read-only. How do I get around this? Please E-mail me w/ any tips. Thank you!
    

    Reply
  • This can be the solution for reopenning problem!!

    Posted by Legacy on 12/17/2001 12:00am

    Originally posted by: JaeMyung Ryoo

    As many windows progammers do I use SourceSafe for my projects.
    And I also faced a reopenning problem when using this macro.
    The macro was pretty good for me but I hate that reopenned
    window's position is not the same as it was.
    So I tried to find me a solution. And I found!!
    Please enjoy this idea!! *^_^*

    --------------------------------------------------
    'keep the previous positions of the window
    FileName = ActiveDocument.FullName
    nWidth = ActiveWindow.Width
    nHeight = ActiveWindow.Height
    nLeft = ActiveWindow.Left
    nTop = ActiveWindow.Top

    .......

    'and reopen the document with previous settings
    Documents.Open(FileName)
    ActiveWindow.Left = nLeft
    ActiveWindow.Top = nTop
    ActiveWindow.Width = nWidth
    ActiveWindow.Height = nHeight

    Reply
  • How do you Make Word documents protected in coding??

    Posted by Legacy on 05/11/2001 12:00am

    Originally posted by: Ivan Cloete

    How do you make a word document protected if you create a word document in your coding ..It must be protected if the generating has finished...

    Ivan

    Reply
  • A much easier way to remove read-only (No macro)...

    Posted by Legacy on 10/27/2000 12:00am

    Originally posted by: Jeroen F. Richters

    Hi there.
    This is how I make my files writable:
    - Go into the Tools/Customize menu.
    - Select the tools tab.
    - At the bottom add a new tool called "Remove Read-Only" or something similar.
    - In the command section type "attrib.exe".
    - In the arguments section type "-R "$(Filepath)"".
    - Check the Close window on exiting checkbox.

    Now if you have the file you want to edit open, then run the Remove Read-Only tool: voila!

    Reply
  • devstudio macros, All project files

    Posted by Legacy on 07/30/2000 12:00am

    Originally posted by: Fredz

    How do you make all files in a projecct writable,
    essentially how do you get all files of a project ?
    Documents only gives you collection of open files.
    I can't believe this shouldn't be possible..i spent
    hours trying to find a way?

    Reply
  • CreateObject give an error ?

    Posted by Legacy on 01/28/1999 12:00am

    Originally posted by: M Y David

    On my computer V5.0 / NT4.0 SP3 , the macro doesn't run
    Do you know why ?

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: February 25, 2015 @ 2:00 p.m. ET / 11:00 a.m. PT Secure Shell (SSH) keys provide unmitigated access for privileged users and applications. However, managing and securing these critical privileged credentials poses a real challenge for organizations, putting sensitive data at risk. In fact, more than 50% of organizations report experiencing an SSH Key related compromise. Check out this upcoming eSeminar and join Adam Bosnian, EVP of Global Business Development at CyberArk, as he discusses the …

  • Even with today's emphasis on mobility, desktop innovation still matters. The ThinkCentre® Tiny-in-One 23 sets a new standard for transformational PC possibilities, bringing breakthrough modular all-in-one ease of use, Intel® performance, integrated security, and legendary durability together with the ThinkCentre Tiny PC family. The ThinkCentre Tiny-in-One 23 gives IT a single desktop platform that carefully balances performance, efficiency, and flexibility. The breakthrough all-in-one form factor …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date