Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Finding read-only & pwd protection attibutes of Word & Excel files

Hi , I'm using the application.filesearch method in an Excel macro to
identify a list of Word and Excel files. I want to check the read-only and
password protection attributes of these word & Excel files and return a flag
to a populated list in Excel.

What object allows me access these attributes? Cheers.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Finding read-only & pwd protection attibutes of Word & Excel files

Application.Filesearch will not cut it for what you want to do. You really
want a file system object. Here is some code to demonstrate them. Note that
in the VB editor you need to reference "Microsoft Scripting Runtime" for this
to work. (Tools - References - Microsoft Scripting Runtime.

Sub ListFiles()
'Must reference "Microsoft Scripting Runtime" library

Dim fso As New FileSystemObject
Dim oCurrentFile As File
Dim oCurrentFolder As Folder
Dim wks As Worksheet
Dim rng As Range

On Error Resume Next
Set wks = Sheets("Sheet1")
Set rng = wks.Range("A2")

Set oCurrentFolder = fso.GetFolder("C:\FPA")

For Each oCurrentFile In oCurrentFolder.Files
rng.Value = oCurrentFile.Name
rng.Offset(0, 1).Value = oCurrentFile.ShortName
rng.Offset(0, 2).Value = oCurrentFile.Path
rng.Offset(0, 3).Value = oCurrentFile.DateCreated
rng.Offset(0, 4).Value = oCurrentFile.DateLastAccessed
rng.Offset(0, 5).Value = oCurrentFile.DateLastModified
rng.Offset(0, 6).Value = oCurrentFile.Size
rng.Offset(0, 7).Value = oCurrentFile.Type
rng.Offset(0, 8).Value = oCurrentFile.Attributes
Set rng = rng.Offset(1, 0)
Next oCurrentFile
End Sub

--
HTH...

Jim Thomlinson


"Eithne R" wrote:

Hi , I'm using the application.filesearch method in an Excel macro to
identify a list of Word and Excel files. I want to check the read-only and
password protection attributes of these word & Excel files and return a flag
to a populated list in Excel.

What object allows me access these attributes? Cheers.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Finding read-only & pwd protection attibutes of Word & Excel files


Searching this forum, I came up with this modified method of searchin
for files and creating a list. To begin with I was using the Fil
Search option, but I couldn't work it to list all the file attributes.
Sub Filelist_wo_Attributes()
'
' Filelist Macro
With Application.FileSearch
.LookIn = "c:\MyDir" '<== Change and set this to your directory
.FileType = msoFileTypeAllFiles
.SearchSubFolders = True
.Execute
For I = 1 To .FoundFiles.Count
Cells(I, 1) = .FoundFiles(I)
Next I
End With
End Sub

This modified code does list all the file attributes, but how do I wor
it to search sub-folders as well.

Sub ListFiles()
'Must reference "Microsoft Scripting Runtime" library (Tools -
References - Microsoft Scripting Runtime)
' Code taken from this forum posted by Jim Thomlinson on 09/26/05
Dim fso As New FileSystemObject
Dim oCurrentFile As file
Dim oCurrentFolder As Folder
Dim wks As Worksheet
Dim rng As Range

On Error Resume Next
Set wks = Sheets("Sheet2")
Set rng = wks.Range("A2")

Set oCurrentFolder = fso.GetFolder("O:\OverFlow\OCP\0859\04\0304")
'<== Set your desired folder path here

For Each oCurrentFile In oCurrentFolder.Files
rng.Value = oCurrentFile.Name
rng.Offset(0, 1).Value = oCurrentFile.ShortName
rng.Offset(0, 2).Value = oCurrentFile.Path
rng.Offset(0, 3).Value = oCurrentFile.DateCreated
rng.Offset(0, 4).Value = oCurrentFile.DateLastAccessed
rng.Offset(0, 5).Value = oCurrentFile.DateLastModified
rng.Offset(0, 6).Value = oCurrentFile.Size
rng.Offset(0, 7).Value = oCurrentFile.Type
rng.Offset(0, 8).Value = oCurrentFile.Attributes
Set rng = rng.Offset(1, 0)
Next oCurrentFile
End Sub
You can consider me a novice to vb programming.

Thanks
Dines

--
reachthepalac
-----------------------------------------------------------------------
reachthepalace's Profile: http://www.excelforum.com/member.php...fo&userid=3172
View this thread: http://www.excelforum.com/showthread.php?threadid=47090

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Finding read-only & pwd protection attibutes of Word & Excel files

http://support.microsoft.com/kb/185601/EN-US/
HOW TO: Recursively Search Directories by Using FileSystemObject

--
Regards,
Tom Ogilvy


"reachthepalace"
<reachthepalace.23jary_1140449409.8071@excelforu m-nospam.com wrote in
message news:reachthepalace.23jary_1140449409.8071@excelfo rum-nospam.com...

Searching this forum, I came up with this modified method of searching
for files and creating a list. To begin with I was using the File
Search option, but I couldn't work it to list all the file attributes.
Sub Filelist_wo_Attributes()
'
' Filelist Macro
With Application.FileSearch
LookIn = "c:\MyDir" '<== Change and set this to your directory
FileType = msoFileTypeAllFiles
SearchSubFolders = True
Execute
For I = 1 To .FoundFiles.Count
Cells(I, 1) = .FoundFiles(I)
Next I
End With
End Sub

This modified code does list all the file attributes, but how do I work
it to search sub-folders as well.

Sub ListFiles()
'Must reference "Microsoft Scripting Runtime" library (Tools -
References - Microsoft Scripting Runtime)
' Code taken from this forum posted by Jim Thomlinson on 09/26/05
Dim fso As New FileSystemObject
Dim oCurrentFile As file
Dim oCurrentFolder As Folder
Dim wks As Worksheet
Dim rng As Range

On Error Resume Next
Set wks = Sheets("Sheet2")
Set rng = wks.Range("A2")

Set oCurrentFolder = fso.GetFolder("O:\OverFlow\OCP\0859\04\0304")
'<== Set your desired folder path here

For Each oCurrentFile In oCurrentFolder.Files
rng.Value = oCurrentFile.Name
rng.Offset(0, 1).Value = oCurrentFile.ShortName
rng.Offset(0, 2).Value = oCurrentFile.Path
rng.Offset(0, 3).Value = oCurrentFile.DateCreated
rng.Offset(0, 4).Value = oCurrentFile.DateLastAccessed
rng.Offset(0, 5).Value = oCurrentFile.DateLastModified
rng.Offset(0, 6).Value = oCurrentFile.Size
rng.Offset(0, 7).Value = oCurrentFile.Type
rng.Offset(0, 8).Value = oCurrentFile.Attributes
Set rng = rng.Offset(1, 0)
Next oCurrentFile
End Sub
You can consider me a novice to vb programming.

Thanks
Dinesh


--
reachthepalace
------------------------------------------------------------------------
reachthepalace's Profile:

http://www.excelforum.com/member.php...o&userid=31729
View this thread: http://www.excelforum.com/showthread...hreadid=470909



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Navigating to Excel files over network slow, but not Word files Newbie123 Excel Discussion (Misc queries) 1 December 2nd 09 01:18 PM
Finding a word in CSV files DennisT Excel Discussion (Misc queries) 4 December 1st 08 04:04 PM
excel to read a row, if word 'x' in then put on other sheet ?? Andy100 New Users to Excel 12 October 13th 05 02:49 PM
Trying to open Excel/Word files error message "Unable to read file RobM Excel Discussion (Misc queries) 1 February 7th 05 08:11 PM
Read about excel - word integration? Jon Peltier[_9_] Excel Programming 0 December 13th 04 01:53 PM


All times are GMT +1. The time now is 03:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"