Results 1 to 7 of 7
  1. #1
    Lounger
    Join Date
    Jan 2001
    Location
    Kingwood, Texas, USA
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Read-Only (VBA/Word/2002 SP-1)

    How can I use VBA to change a Word doc from ReadOnly = True to ReadOnly = False?

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Read-Only (VBA/Word/2002 SP-1)

    Do you mean the file attributes? If so, you can't directly, but with the filesysobject you can easily from withing VBA.

    See here for the lowdown and sample code: http://msdn.microsoft.com/library/default....oattributes.asp
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Read-Only (VBA/Word/2002 SP-1)

    The only way I know is to execute the command ActiveDocument.SaveAs
    This will save the document as a new file which is now writeable.

    StuartR

  4. #4
    Lounger
    Join Date
    Jan 2001
    Location
    Kingwood, Texas, USA
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Read-Only (VBA/Word/2002 SP-1)

    I already had the file "saved as" in my macro. What I wanted to do was delete the read only file so that I could then "save as" again using the original filename. (I would then kill the file with the wrong name.) Word is occasionally turning users' files into Read-Only files as they are working on them, and I was hoping to give them a quick way to recover from this. I'm sure Kevin's solution would work, but I don't know how to use VB Script & haven't had the time to try to figure it out.

  5. #5
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Read-Only (VBA/Word/2002 SP-1)

    Margot,

    Here is a little procedure that will do what you need.

    Sub ReplaceReadOnly()

    Dim strPath As String
    Dim strCurrentName As String

    'Get Current Path and filename
    strPath = ActiveDocument.Path
    strCurrentName = ActiveDocument.Name

    'Save As temp file
    ActiveDocument.SaveAs strPath & "tempFileName.doc"
    'Delete old file
    Kill strPath & "" & strCurrentName
    'Resave as old file name
    ActiveDocument.SaveAs strPath & "" & strCurrentName
    'Delete Temp File
    Kill strPath & "tempFileName.doc"

    End Sub

    What this does is saves the active document under a temporary name, delete's the original, resaves it with the original file name and then delete's the temp one.

    But the big question is why are the documents being changed to Read Only? I would suspect that there are temp files that aren't cleanup when Word gets shut down, or when Word crashes. So you may have bigger problems than giving your users a "quick way to recover".
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  6. #6
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Read-Only (VBA/Word/2002 SP-1)

    Geez, sorry about that. I tested it and it ran fine for me. Now I realize my mistake <img src=/S/doh.gif border=0 alt=doh width=15 height=15>.

    I forgot to flip the Read-Only flag. <img src=/S/blush.gif border=0 alt=blush width=15 height=15>
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

  7. #7
    Lounger
    Join Date
    Jan 2001
    Location
    Kingwood, Texas, USA
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Read-Only (VBA/Word/2002 SP-1)

    <P ID="edit" class=small>(Edited by gwhitfield on 29-Jan-03 21:03. Hot links added)</P>I knew about the temp files. http://www.mvps.org/word/FAQs/AppErrors/Lo...ilesContent.htm has instructions for dealing with them & other disk messies. However, we also have another issue, which is that we're using a set of automated templates (plus an add-in) programmed by others. I am now working on the next release & we have not so far experienced any "read onlification" while testing the new add-in.

    I tested your procedure on a read-only file and got a "Path/File access error" at the first line starting with "Kill." Since the file was on my C drive, I'm pretty sure this means Word won't let me kill a read only file. Your procedure was very similar to one of my attempts, which also gave me an error message when attempting to kill the read-only file.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •