PDA

View Full Version : make each doc read only



gibbo1715
11-28-2005, 08:40 AM
can anyone help me out with a piece of code please that will save me a load of time

I have a directory that contains 300 word documents

i need to make them all read only

Tried this to no avail :(

Dim Path As String
Path = ActiveDocument.Path
For Each Document In Path
SetAttr PathName:=ActiveDocument.Path, Attributes:=vbReadOnly
Next
End Sub

Any Ideas

Cheers

Gibbo

Marcster
11-28-2005, 09:07 AM
Hi Gibbo :hi:,

Try this:
Sub ChangeAllFilesToReadOnly()
Dim Path As String
Path = ActiveDocument.Path
Dim fso, f, f1, fc
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(path)
Set fc = f.Files
For Each f1 In fc
f1.Attributes = f1.Attributes + 1 '1=Read only,2=hidden,4=system,
',32=Archive,0=No attributes
Next
End Sub

HTH,

Marcster.

TonyJollans
11-28-2005, 11:45 AM
I would check first that the file attruibute is not already read-only otherwise you may not get the results you want. (f1.attributes mod 2 = 0 or similar)

fumei
11-28-2005, 12:36 PM
Always a good idea to check the water first.....