#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default XP problem

Have just moved up from 98 to xp and have found that the following code will
not work, any ideas why ???

at the ".FileName" line i am getting a runtime error 5 "Invalid procedure
call or argument"
It only throws this fault if it finds a file, i.e. if I used "*.hhh" the
problem does not arisre because it will not find any such files


With Application.FileSearch
.LookIn = "C:\Myfile\Preview"
.SearchSubFolders = False
.FileName = "*.jpg"
.Execute
For i = 1 To .FoundFiles.Count

Next i
End With


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default XP problem

How about if you use:
..filename = ".jpg"

But application.filesearch seems to cause trouble in some versions of windows
(some of the time).

You may want to go back to using dir().

Option Explicit
Sub testme01()

Dim myNames() As String
Dim fCtr As Long
Dim myFile As String
Dim myPath As String

'change to point at the folder to check
myPath = "c:\my documents\my pictures"
If Right(myPath, 1) < "\" Then
myPath = myPath & "\"
End If

myFile = ""
On Error Resume Next
myFile = Dir(myPath & "*.jpg")
On Error GoTo 0
If myFile = "" Then
MsgBox "no files found"
Exit Sub
End If

'get the list of files
fCtr = 0
Do While myFile < ""
fCtr = fCtr + 1
ReDim Preserve myNames(1 To fCtr)
myNames(fCtr) = myFile
myFile = Dir()
Loop

If fCtr 0 Then
For fCtr = LBound(myNames) To UBound(myNames)
'code to process the files.
'say
MsgBox myPath & myNames(fCtr)
Next fCtr
End If

End Sub



Stuart wrote:

Have just moved up from 98 to xp and have found that the following code will
not work, any ideas why ???

at the ".FileName" line i am getting a runtime error 5 "Invalid procedure
call or argument"
It only throws this fault if it finds a file, i.e. if I used "*.hhh" the
problem does not arisre because it will not find any such files

With Application.FileSearch
.LookIn = "C:\Myfile\Preview"
.SearchSubFolders = False
.FileName = "*.jpg"
.Execute
For i = 1 To .FoundFiles.Count

Next i
End With


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default XP problem

Hi Stuart,

With the problematic workbook open, in the VBE:

Tools | References

and check that you have a reference set to the MS office object library.


---
Regards,
Norman


"Stuart" wrote in message
...
Have just moved up from 98 to xp and have found that the following code
will not work, any ideas why ???

at the ".FileName" line i am getting a runtime error 5 "Invalid procedure
call or argument"
It only throws this fault if it finds a file, i.e. if I used "*.hhh" the
problem does not arisre because it will not find any such files


With Application.FileSearch
.LookIn = "C:\Myfile\Preview"
.SearchSubFolders = False
.FileName = "*.jpg"
.Execute
For i = 1 To .FoundFiles.Count

Next i
End With




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
Colon at the end of excel file name(ex: problem.xls:1, problem.xls financeguy New Users to Excel 2 January 15th 10 01:15 AM
Started out as an Access problem. Now an Excel problem RobertM Excel Discussion (Misc queries) 2 April 26th 06 07:30 PM
problem with a conditional max problem Brian Cornejo Excel Discussion (Misc queries) 1 February 18th 05 06:25 PM
Problem when multipple users access shared xl-file at the same time, macrocode for solve this problem? OCI Excel Programming 0 May 16th 04 10:40 PM


All times are GMT +1. The time now is 01:13 AM.

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"