Make a file read only

I

Indu Aronson

I am using Word 2002.

I have several files where I need to make a lot of
changes and once I am done I would like to make them read
only.

Is there a way that I can create a macro, add it to a
custom toolbar button? It would be really convenient if I
could click a button and make the active document read
only.

Currently, I have this, which I made through the recorder:

With ActiveDocument
.ReadOnlyRecommended = True
.Password = ""
.WritePassword = ""
.RemovePersonalInformation = False
End With

When I click on a button with this code, close out of hte
file and open it, I get a promtp as to whether I want to
open the file as read only, rather than forcing that
attribute on that file.

Thanks!
 
H

Helmut Weber

Hi Indu,
like this, modified from the online help:
Sub Macro1()
Dim oFileSys As Object
Dim oFileObj As Object
Dim sFullNam As String
sFullNam = ActiveDocument.FullName
ActiveDocument.Save
ActiveDocument.Close
Set oFileSys = CreateObject("Scripting.FileSystemObject")
Set oFileObj = oFileSys.GetFile(oFileSys.GetFileName(sFullNam))
oFileObj.Attributes = 1 ' ReadOnly
Set oFileObj = Nothing
Set oFileSys = Nothing
End Sub
 
I

Indu

Helmut:

Thank you very much for your help. When I ran the code, I
got the following message on this line:

Ivalid Procedure Call or Argument

Set oFileObj = oFileSys.GetFile(oFileSys.GetFileName
(sFullName))

I don't understand how to fix this. Can you please help
again? Thank you.
 
H

Helmut Weber

Hi Indu,
apart from other possible complications,
I used 8 character long variable names.
It may seem odd to some people, may be I should do away with it.
So I used "sFullNam", whereas in you reply there is "sFullName".
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top