Sub cannot run (Error 5)

M

Max

I'm trying to run the sub below (using Excel 97, Win XP),
but kept hitting:

Invalid procedure call or argument (Error 5)

Debug pointed at this line:
.FileName = "*.*"

The number of files in the folder: D:\Program Files\Erlang\CalcA
is less than 50

-------
Sub ListFiles02()
'Using FileSearch to list the files in a directory
Dim i As Integer
i = 1
With Application.FileSearch
.NewSearch
.LookIn = "D:\Program Files\Erlang\CalcA"
.FileName = "*.*"
.SearchSubFolders = True
'.SearchFolders = False
.Execute

For i = 1 To .FoundFiles.Count
Range("B" & i).Value = .FoundFiles(i)
Range("C" & i).Value = FileDateTime(.FoundFiles(i))
Range("D" & i).Value = FileLen(.FoundFiles(i))
Next
End With
End Sub
 
P

Patrick Molloy

as it is, the code works fine for me. Try looking in another drive - D is
often used for CD/DVD
 
M

Max

Thanks, Patrick, but still no go here, I'm afraid. Tried putting in other
valid drives / paths, all attempts failed to run. Same error msg, same debug
line.

Even tried changing the debug line to say,:
..FileName = "*.bmp"
but it still failed to clear this line
 
P

Patrick Molloy

try

.FileName = "*"


Max said:
Thanks, Patrick, but still no go here, I'm afraid. Tried putting in other
valid drives / paths, all attempts failed to run. Same error msg, same debug
line.

Even tried changing the debug line to say,:
..FileName = "*.bmp"
but it still failed to clear this line
--
Rgds
Max
xl 97
 
K

kounoike

your code works with no problem for me.
How about opening new workbook, and copy your posted code to the new
workbook, and then try it on the new workbook?

keizi
 
D

Dave Patrick

Are you logged on as local administrator? Code 5 generally = "Access is
denied" Also try another machine.

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

:
| I'm trying to run the sub below (using Excel 97, Win XP),
| but kept hitting:
|
| Invalid procedure call or argument (Error 5)
|
| Debug pointed at this line:
| .FileName = "*.*"
|
| The number of files in the folder: D:\Program Files\Erlang\CalcA
| is less than 50
|
| -------
| Sub ListFiles02()
| 'Using FileSearch to list the files in a directory
| Dim i As Integer
| i = 1
| With Application.FileSearch
| .NewSearch
| .LookIn = "D:\Program Files\Erlang\CalcA"
| .FileName = "*.*"
| .SearchSubFolders = True
| '.SearchFolders = False
| .Execute
|
| For i = 1 To .FoundFiles.Count
| Range("B" & i).Value = .FoundFiles(i)
| Range("C" & i).Value = FileDateTime(.FoundFiles(i))
| Range("D" & i).Value = FileLen(.FoundFiles(i))
| Next
| End With
| End Sub
| -------
|
| Appreciate any insights. Thanks.
|
| --
| Rgds
| Max
| xl 97
| ---
| Singapore, GMT+8
| xdemechanik
| http://savefile.com/projects/236895
| --
|
|
 
M

Max

I'm stumped??, just tested, the sub runs ok on my home PC: Excel 97, Win 98.
But it continues to fail in the other, earlier environ: Excel 97, Win XP
Is there anything else I can try to make it work over there ?
 
M

Max

As responsed further in the other branch ... just tested, the sub runs ok on
my home PC: Excel 97, Win 98. But it continues to fail in the other, earlier
environ: Excel 97, Win XP. Is there anything else I can try to make it work
over there ?
 
M

Max

Dave, thanks for insights. Just tested, the sub runs ok on my home PC: Excel
97, Win 98. But it continues to fail in the other, earlier environ: Excel
97, Win XP
Are you logged on as local administrator?
How do I check this in Win XP ?
--
Rgds
Max
xl 97
---
Singapore, GMT+8
xdemechanik
http://savefile.com/projects/236895
--
Dave Patrick said:
Are you logged on as local administrator? Code 5 generally = "Access is
denied" Also try another machine.

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect
 
D

Dave Patrick

Start|Run and type

control userpasswords2

then properties for your user account.

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

:
| Dave, thanks for insights. Just tested, the sub runs ok on my home PC:
Excel
| 97, Win 98. But it continues to fail in the other, earlier environ: Excel
| 97, Win XP
|
| > Are you logged on as local administrator?
| How do I check this in Win XP ?
| --
| Rgds
| Max
| xl 97
| ---
| Singapore, GMT+8
| xdemechanik
| http://savefile.com/projects/236895
| --
 
M

Max

Ok, these were my user properties listed:
Debugger Users; Tivoli_Admin_Privileges; Administrators; Users
(I don't really know how to intrepret the properties <g>)

The sub still stubbornly refuses to run ..
 
D

Dave Patrick

Check that you can manually traverse the folders in question with your
logon. Try some other directories possibly with SearchFolders = False

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

:
| Ok, these were my user properties listed:
| Debugger Users; Tivoli_Admin_Privileges; Administrators; Users
| (I don't really know how to intrepret the properties <g>)
|
| The sub still stubbornly refuses to run ..
| --
| Rgds
| Max
| xl 97
| ---
| Singapore, GMT+8
| xdemechanik
| http://savefile.com/projects/236895
| --
|
|
 
M

Max

Dave Patrick said:
Check that you can manually traverse the folders
in question with your logon.

Confirmed, no problem. I can see the folder contents.
Try some other directories
possibly with SearchFolders = False

Tried other directories, and with the suggested setting
but it still hangs at the same line:
..FileName = "*.*"
 
N

NickHK

Max,
People always seem to get unexpected behaviour with .Filesearch, across
versions of Windows and Office.
Dir( ) produces relaible results.

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top