+ Reply to Thread
Results 1 to 7 of 7

Problem using Name As to move files after reading CSV Data into a WorkSheet

  1. #1
    Registered User
    Join Date
    03-02-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    5

    Problem using Name As to move files after reading CSV Data into a WorkSheet

    Hi,

    Just learning VBA and have pieced together this subroutine from various sources that did similar things but not quite what I wanted. Any help appreciated. The sub reads all *.csv files in a Folder and places the contents into a single Worksheet, one below the other. That bit works great.

    Then I want to move each file that has been read to a new Directory so it still exists but will not be imported again when the macro is run next.

    I cannot get the Name As section of the code to work. The Macro always stops with Run Time Error 75 - Path/File access error. I have tried simple Path & File names (as can be seen commented out in the code) and it still does not work. I tried using FileCopy and that works no problem but that doesn't move the files.

    I'm using Excel 2010 on Win7 and when I copy files myself in Explorer, I have to "provide administrator permission" to move & delete files etc.
    The csv files are exported from another program that is run "as Administrator".

    Here is the code, many thanks for any help ...
    Please Login or Register  to view this content.
    rgds mcdirt
    Last edited by JosephP; 03-04-2013 at 11:26 AM. Reason: added code tags-please use them in future

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Problem using Name As to move files after reading CSV Data into a WorkSheet

    For a self-proclaimed noob, your code is well written. Good job.

    Try putting a \ at the end of the new path.

    NewPath = "C:\Users\Brian\"

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,791

    Re: Problem using Name As to move files after reading CSV Data into a WorkSheet

    Maybe:

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    03-02-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Problem using Name As to move files after reading CSV Data into a WorkSheet

    Thanks for replies ...

    AlphaFrog - I like clean code sorry, the final \ in NewPath was there but got lost when fiddling just before copying the code here, routine still gets the error with correct NewPath.
    TMShucks - with your code, I get the same error but now on the Kill statement.

    Would prefer to get Name As working if I can as it seems safer - if I use Copy & Kill then I'll need to add error checking code to make sure the Kill only proceeds if the Copy works.

    rgds mcdirt

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Problem using Name As to move files after reading CSV Data into a WorkSheet

    Are you logged on Windows with Administrator privileges? If no, can you test it logged on as an Administrator?

  6. #6
    Registered User
    Join Date
    03-02-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Problem using Name As to move files after reading CSV Data into a WorkSheet

    Double checked User Accounts and I show as Administrator.

    rgds mcdirt

  7. #7
    Registered User
    Join Date
    03-02-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Problem using Name As to move files after reading CSV Data into a WorkSheet

    Was something to do with Permissions where the source files were.
    I moved them manually then tried it and it worked perfectly so I'll just write a batch file to move the files every hour.
    Thanks for the help.

+ 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