View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
AA2e72E AA2e72E is offline
external usenet poster
 
Posts: 400
Default can I list only the protected?

I do not believe there is a way to tell whether an XLS or DOC file contains
codes and is protected by a password.

1. You'd need to know the password to be able to open the XLS or DOC. I do
not know of a way of specifying the password to the VBE in orer to be able to
open the project and count the lines of code in it, if any.
2. Use this to count whether it contains code:

Function xx() As Double
abc = 0
For Each comp In Application.VBE.ActiveVBProject.VBComponents
abc = abc + comp.codemodule.countoflines
Next
xx = abc
End Function

This will return 0 if there is no code or a positive integer if it does. In
order to automate this, you'd need to use VB or VBA or VBScript.


"J_J" wrote:

Thank you AAe72E,
what I meant is thouse *.xls and *.doc files which have a "password" to be
viewed. Or thouse *.xls or *.doc files which has a macro but the macro is
password protected and the macro cant be viewed. I do not need to
unlock/remove the passwords from them. I just want to identify them.
Regards
J_J



"AA2e72E" wrote in message
...
I am not sure what you mean by protected.

There is a programmatic solution using File System Object. You must be
aboe
to write recursive code. One way to avoid this is as follows:

1. Get to the Command Prompt
2. Type:
dir d:\*.doc d:\mylist.txt /b /s
<ENTER
dir d:\*.xls d:\myfile.txt /b /s
<ENTER

NOTE: the second dir command has whereas the first has only.

/b means bare output, i.e. file name only
/s means span all sub directories

means create or overwrite the file name that follows.
means append to the file name that follows.


At the end, the file d:\myfile.txt contains the names of all DOC files,
followed by the names of all XLS files.

If by 'protected' you mean whether the files have the readonly/archive,
hidden, system flags set, you can use the FileSystemObject.

Use the GetFile method against each line of d:\mytext.txt and then query
the
Attributes property of the object returned by GetFile.

"J_J" wrote:

Hi,
Can we list the *.doc and *.xls files in all dir/sub directories of drive
D:
which ARE protected by filename, loacation, size via VBA?
TIA
J_J