+ Reply to Thread
Results 1 to 11 of 11

FileName = Dir() - Invalid procedure call or argument

  1. #1
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    FileName = Dir() - Invalid procedure call or argument

    This error happens in the Read CSV Module.

    There is something funky going on with this code.

    In the code, I pass an argument to a function, GetDate. The argument is a file name with like "ABC_yyyymmdd.csv" and the function is designed to return the string MMM DD. As an intermediate step in the function, it changes the parameter passed to it to YYYYMMDD. It also changes the name of the file in the calling program. FileName is NOT a global. I "worked around" the issue with a two-step and created a variable called DateName and it gets destroyed by the parsing process.

    I don't think I am doing anything to change where dir is pointing.

    Attached is the file, the misbehaving macro is AddPages. The zip file contains test CSV files. Cells B1 and B2 on the control panel can be used to configure where these CSV files are read and where they get deposited to when they are processed. So you should be able to replicate the issue.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: FileName = Dir() - Invalid procedure call or argument

    There is no AddPages macro

  3. #3
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: FileName = Dir() - Invalid procedure call or argument

    ModReadCSV
    Please Login or Register  to view this content.

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: FileName = Dir() - Invalid procedure call or argument

    At the end of the loop make this change
    Please Login or Register  to view this content.
    You're changing the dir()when you move the files after processing

  5. #5
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: FileName = Dir() - Invalid procedure call or argument

    You cant use DIR for lopping files and modifying them. Use FSO for modifying them inside your DIR loop.
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: FileName = Dir() - Invalid procedure call or argument

    @dflak
    Thanks for the Rep.

    @Zer0Cool
    The code is not modifying the csv files, only moving them.

  7. #7
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: FileName = Dir() - Invalid procedure call or argument

    I am "getting away" with this in other code and I decided to try to figure out why. In those cases, I have a program that reads a mail folder, gets the messaged and downloads the attachments to the folder I subsequently want to read for processing. These files are read into the directory in a specific order, and they are probably read out in the same order. In other words, by the time I hit the Filename = Dir() command, DIR is already "done with" the file and all the files it "sees" in front of it are still there.

  8. #8
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: FileName = Dir() - Invalid procedure call or argument

    Ok let me re-phrase my statement, you cant use DIR inside DIR to evaluate other things.

    Please Login or Register  to view this content.
    Cannot be inside the DIR loop. Use FSO to work with file objects inside the DIR loop

  9. #9
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: FileName = Dir() - Invalid procedure call or argument

    If you try the code you'll find that it works.

  10. #10
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: FileName = Dir() - Invalid procedure call or argument

    I think I see what is going on here.

    This
    Please Login or Register  to view this content.
    Blows the "stack" of file names.

    When followed by
    Please Login or Register  to view this content.
    a new "stack" is created.

    Using fso.FileExists() - preserves the original stack.

  11. #11
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: FileName = Dir() - Invalid procedure call or argument

    @dflak You got it. Using DIR within the loop is essentially breaking the loop, hence using FSO to resolve the problem.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. FileName = Dir() - Invalid procedure call or argument
    By dflak in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-03-2018, 09:56 AM
  2. Invalid Procedure Call or Argument
    By theTaoJones in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-27-2018, 03:23 PM
  3. Invalid procedure call or argument?
    By taylorsm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-03-2017, 10:15 AM
  4. Invalid procedure call or argument
    By Netzqua in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-24-2016, 11:45 AM
  5. Invalid procedure call or argument
    By krish T in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-31-2010, 10:01 AM
  6. Invalid procedure call or argument
    By mqdias in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-08-2007, 06:01 AM
  7. Invalid Procedure call or argument
    By T De Villiers in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-25-2006, 10:05 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1