+ Reply to Thread
Results 1 to 8 of 8

VB Run-time error 1004 when opening file from previously chosen folder

  1. #1
    Registered User
    Join Date
    11-11-2012
    Location
    Winnipeg, Canada
    MS-Off Ver
    Excel 2010
    Posts
    3

    VB Run-time error 1004 when opening file from previously chosen folder

    Hello Everyone,

    This is my first post on the forum and my first programming attempt. Thus, please be understanding if I will ask basic questions OK, cutting to the chase...

    I'm trying to write a macro which would import data from multiple .csv files to one worksheet. I have few hundreds files, each file has only one worksheet named the same as the file and all files are in the same directory. In each worksheet are 3 columns and more than 2k rows of data. I need to put all of that (except last 9 rows from each file) to one worksheet one under another (one table). Using some codes from forums and trail and error method I end up with following code:

    Please Login or Register  to view this content.
    Unfortunately, that worked only for the testing folder where I copied 3 files. When I try to run it for other folder or even for the test folder but with different files I get "Run-time error '1004'". Full error msg:

    'xxx.csv' could not be found. Check the spelling of the file name, and verify that the file location is correct.

    If you are trying to open the file from list of mostrecently used files, make sure that the file has not been renamed, moved or deleted.
    Where 'xxx.csv' is first .csv file in the folder alphabetically. Also, when it works it will ask me if I want to keep content of Clipboard every time it closes next file. Is there any way to confirm that automatically?

    I would appreciate any help.

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: VB Run-time error 1004 when opening file from previously chosen folder

    Does this have to be done from Excel? I'd do this from the cmd prompt.

    Where

    Please Login or Register  to view this content.
    For your code, I suspect that you need to explicitly put the filepath in the open command, just the name of the csv you're opening isn't sufficient

    i.e
    Please Login or Register  to view this content.
    Last edited by Kyle123; 11-12-2012 at 12:29 PM.

  3. #3
    Registered User
    Join Date
    11-11-2012
    Location
    Winnipeg, Canada
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: VB Run-time error 1004 when opening file from previously chosen folder

    For your code, I suspect that you need to explicitly put the filepath in the open command, just the name of the csv you're opening isn't sufficient
    Kyle, that worked like a charm. BIG thank you.
    Would you be able also advise something to avoid that question about the Clipboard?

  4. #4
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: VB Run-time error 1004 when opening file from previously chosen folder

    If you still want to do it in excel...

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: VB Run-time error 1004 when opening file from previously chosen folder

    Quote Originally Posted by damkru View Post
    Would you be able also advise something to avoid that question about the Clipboard?
    Have to use below line to avoid the large data prompt.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    11-11-2012
    Location
    Winnipeg, Canada
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: VB Run-time error 1004 when opening file from previously chosen folder

    I still want to use Excel because I need to cut first and last 9 rows from origin files. Combining all suggestions I got macro that does exactly what I wanted. Thank you very much for your help.

    This is final version of the code:

    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: VB Run-time error 1004 when opening file from previously chosen folder

    If query is resolved, please update the status of thread to solved

  8. #8
    Valued Forum Contributor
    Join Date
    11-02-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    564

    Re: VB Run-time error 1004 when opening file from previously chosen folder

    Sorry didnt notice that its already updated. Please ignore

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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