Hello. (Excel 2003)
I have a procedure which uses the FileSystemObject of the Windows Scripting Runtime to list subfolders.
It falls over with a Permission Denied error message. I assume the folder might be hidden or a system folder?
It loops with:
For Each SubFolder In OfFolder.SubFolders
How can I either ignore this subfolder or list it despite its attribute? Thanks, Andy.
FileSystemObject and hidden files
-
- SilverLounger
- Posts: 2403
- Joined: 05 Feb 2010, 22:21
- Location: London ENGLAND
FileSystemObject and hidden files
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
-
- Administrator
- Posts: 79676
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: FileSystemObject and hidden files
Try using an error handler:
Code: Select all
Sub MyCode()
...
On Error GoTo ErrHandler
For Each SubFolder In OfFolder.SubFolders
...
...
ContinueHere:
Next SubFolder
....
Exit Sub
ErrHandler:
If Err = 70 Then
' Permission denied
Resume ContinueHere
Else
MsgBox Err.Description, vbExclamation
End If
End Sub
Best wishes,
Hans
Hans
-
- SilverLounger
- Posts: 2403
- Joined: 05 Feb 2010, 22:21
- Location: London ENGLAND
Re: FileSystemObject and hidden files
That's a solution, thank you. It's a shame I can't check the file attribute before the error is generated, but never mind. Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.