Set objFileSystem = CreateObject("Scripting.Fi
Set objFile = objFileSystem.GetFile(tFil
objFile.Attributes = 0 ' This sets it to not read only
Main Topics
Browse All TopicsI want to open a readonly Word document, turn off the readonly flag, allow changes, save the document and then turn the readonly flag back on. I am using the following code in my Document_Open() event which does turn off the readonly flag on the file, but apparently Word still thinks the document is readonly and won't let me save it. Is there anyway to "refresh" the activedocument readonly property to make it match the current file attribute?
Private Sub Document_Open()
Dim ROname As String
Dim ROobj, ROcr
ROname = ActiveDocument.FullName
If ActiveDocument.ReadOnly = True Then
Set ROobj = CreateObject("Scripting.Fi
Set ROcr = ROobj.GetFile(ROname)
ROcr.Attributes = 0
Set ROcr = Nothing
Set ROobj = Nothing
ActiveDocument.ProtectionT
End If
End Sub
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Do it in the VBA Code it self.
Private Sub Document_Open()
Dim ROname As String
Dim ROobj, ROcr
dim fileattribute1 as int
Set ROobj = CreateObject("Scripting.Fi
Set ROcr = ROobj.GetFile(ROname)
fileattribute1 = ROcr.attributes
ROcr.Attributes = 0
ROname = ActiveDocument.FullName
If ActiveDocument.ReadOnly = True Then
ActiveDocument.ProtectionT
End If
End Sub
and then use fileattribute1 for setting it back.( for this set fileattribute1 as global variable)
How about this wild guess...
1. The document open event calls a VB program thru shell and passes the file information. And then closes the document.
2. The VB prog called first finds the read attribute setting using the FileSystemObject. Then sets it to allow write. Opens up the document thru it . Doing this it passes the read flag to the document. Exit out of VB prog
3. the During the document close event another VB program is called which closes the document and then sets the read flag on.
In all this you would also need to take care to decide whether the doc was opened thru VB or directly by maintaing another flag and passing them thru each opening and closing of the word. This variable will decide the actions to be taken.
Actually, this is part of a Visual Foxpro application. What I ended up doing is setting the readonly attribute on the file off in VFP using Filesystemobject and then opening the Word document. Code in the Word document close event saves the the document and then uses Filesystem object to turn the readonly flag back on.
Similar to your suggestion. Not exactly what I wanted...but it will work.
Business Accounts
Answer for Membership
by: pra_kumar03Posted on 2004-11-05 at 11:47:31ID: 12508008
You can set the read only flga off using the FileSystemObject to read the current attribute . then change to allow changes. THen open the worrd object , do whatever you want to do. Next you save it and close it. then use the FileSystemObject to set it back to the actual attribute.