Results 1 to 5 of 5
  1. #1
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error w/ Application.FileSearch w/ .FileName

    Just had an (inexpert) play around and with the assistance of Help on 'LookIn' found this to work on Win2000 using Word2K:

    Set fs = Application.FileSearch
    With fs
    .LookIn = "Eocuments"
    .FileName = "*.*"
    If .Execute > 0 Then
    numoffiles = .FoundFiles.Count
    Else: numoffiles = 0
    End If
    End With

    (I obviously used a folder name that was valid here.)

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Error w/ Application.FileSearch w/ .FileName

    Like Leif, I've tried this on Word/Win 2000, and it doesn't hang on that line - so something mysterious is going on.

    First question though: how are you getting this to run without some kind of .Execute statement? (or did you just leave it out of the example and I'm being [img]/w3timages/icons/doh.gif[/img])

    A 'grasp at straws' suggestion would be, in case for some perverse reason the "*.*" is causing a problem, would be to explicitly add an extension, like "*.doc". You could also precede this line with a ".FileType = msoFileTypeWordDocuments" if your search is limited to Word files.
    You might also do a test searching for an explicit filename i.e. "Test.doc".

    Don't know if any of the above is going to help, though.

  3. #3
    New Lounger
    Join Date
    Sep 2002
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error w/ Application.FileSearch w/ .FileName

    Lief is correct in that I didn't bother to complete the code--it does need the execute statement to actually run. However, it hangs up anyway. I have also tried other variations of the wildcard *. Any use causes the problem (whether "*.doc" or "filename.*". Using an explicit file name gets it to work! I've also checked folder settings in Win 2000 (such as attributes, and sharing) and no changes in these settings seems to make a difference. (Note: thanks for code for Word files, but I'm accessing text files without "doc" extensions.)

    I have a strong feeling that it is not necessarily Word, but the interaction between Word and Win 2000--some kind of sharing thing, maybe? (I have had one other very mysterious Win 2000 problem where my designated home directory folder for Web publishing becomes inaccessible with FrontPage 2000--unless I change the name and designate new named folder in Web Manager. Also seems a sort of sharing violation.)

    Anyway, thanks for suggestions. And for those who may stumble on this, it may be a bit hopeless unless you know something about Win 2000. --Or maybe not. Perhaps I'll try the Win 2000 forum.

    Mark

  4. #4
    New Lounger
    Join Date
    Sep 2002
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error w/ Application.FileSearch w/ .FileName "*.*"

    I am trying to use the code below to get a file count for directory c:0-New. I'm on Win 2000 and get error message: "Run-time Error '5'. Invalid procedure call or argument." at the .FileName = "*.*" line.

    I don't get this error on my NT 4.0 setup at work. Can't understand why it works one place, not the other.

    Any help, suggestions would be greatly appreciated.


    With Application.FileSearch
    .LookIn = "C:0-New"
    .FileName = "*.*"
    .Execute
    NumOfFiles = .FoundFiles.Count
    End With

  5. #5
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error w/ Application.FileSearch w/ .FileName

    Just as a matter of interest:
    Have you any other code running before what you posted?
    Will it work if you define a different folder?
    How many files do you have in that folder?
    Do you have any Word "~" files in that folder?
    Are there any hidden files in the folder?

    I don't know if any answers to the above will help directly, but may spark something somewhere.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •