Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if all files are protected

Status
Not open for further replies.

wmbb

Technical User
Jul 17, 2005
320
NL
I want to check if all WORD files in de directory "folder" are protected.
If not than I want the macro to protect the document.

I was thinking about a code like

Code:
For Each f In fso.GetFolder(folder).Files

If f.ProtectionType = wdNoProtection Then
    f.Protect Password:=ProtectPW, NoReset:=False, Type:=wdAllowOnlyReading, UseIRM:=False, EnforceStyleLock:=False
End If

Next

Can somebody help with a working code ?

 
You can't proceed with closed files.
Possible peocedure:
1) add On Error Resume next statement at the beginning,
2) get a filtered list of file names (possible with Dir function too, see vba help file),
3) try to open each file,
4) if no error in step (2) - set protection to a document, save and close it,
5) if error in step (2) - clear the error,
6) go to next file (if exists).

combo
 
Okay, thank you for your response.
The fact that this isn't possible with closed files is the end of this project.
I don't want to open up all files to check the protection.
We have to check the protection in a previous step.
Thanks again for this info.
 
You can still access some file properties from the file system level. If you code the protection in file comments for instance, you can access it whatever the protection is:
Code:
Dim sh As Shell32.Shell
Dim shfi As Shell32.ShellFolderItem
Const FMTID_SummaryInfo_Comment As String = "{F29F85E0-4FF9-1068-AB91-08002B27B3D9} 6"
Set sh = New Shell32.Shell
Set shfi = sh.NameSpace(Drive&Path).ParseName(FileName)
MsgBox shi.ExtendedProperty(FMTID_SummaryInfo_Comment)
Early binding above requires reference to shell32.dll.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top