+ Reply to Thread
Results 1 to 11 of 11

Error when trying to move a file via VBA

  1. #1
    Registered User
    Join Date
    02-20-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    30

    Error when trying to move a file via VBA

    Hello! I am trying to get a button on my spreadsheet which will move the workbook from a "In Progress" folder to a "Completed" folder, however when I run it, it says "File Not Found", but if I key in the workbook name instead of "ThisWorkbook.Name", it works fine. Any ideas on a work around? Or why its not working? Thanks in advance!


    Please Login or Register  to view this content.
    Solved! by Kelshaer - Thank you!!

    Please Login or Register  to view this content.
    (file is on a sharepoint)
    Last edited by cg0789; 03-09-2012 at 10:19 AM. Reason: Solved!

  2. #2
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: Error when trying to move a file via VBA

    Try this

    Please Login or Register  to view this content.
    Regards,
    Khaled Elshaer
    www.BIMcentre.com

    Remember To Do the Following....
    1. Thank those who have helped you by clicking the Star below their post.
    2. Mark your post SOLVED if it has been answered satisfactorily:
    • Select Thread Tools (on top of your 1st post)
    • Select Mark this thread as Solved

  3. #3
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Error when trying to move a file via VBA

    Is the workbook you wish to move the currently open workbook (ie the one the code resides in)? If so, I would think you would get a File Access error rather than file not found unless you have written the path out wrong.

  4. #4
    Registered User
    Join Date
    02-20-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Error when trying to move a file via VBA

    Kelshaer:

    That half-worked, and might be giving us some insight to what the problem is, now P:\ is a mapped network drive (I don't know whether that could be affecting this or not?), but now it errors out at "Kill OldFileName" at the end of the script which make me believe its a error deleting the file from a network drive, what is interesting, if I replace "OldFileName" with the exact file location, it works just fine. Any ideas?

    Quote Originally Posted by Kelshaer View Post
    Try this

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: Error when trying to move a file via VBA

    cg0789:
    It doesnt matter if it is on a network drive.
    About the line Kill OldFileName, this is very strange. I tried it on a network drive here and it worked perfectly. And if it works with the file name instead of the variable then please run the below macro and see the results
    Please put the exact file location where indicated within the code

    Please Login or Register  to view this content.

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Error when trying to move a file via VBA

    Please Login or Register  to view this content.



  7. #7
    Registered User
    Join Date
    02-20-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Error when trying to move a file via VBA

    Ok, starting to make some more sense, ThisWorkbook.FullName is pulling the "exact location" of the file, which is on a SharePoint, not the P:\ directory which it is mapped to.

    Quote Originally Posted by Kelshaer View Post
    cg0789:
    It doesnt matter if it is on a network drive.
    About the line Kill OldFileName, this is very strange. I tried it on a network drive here and it worked perfectly. And if it works with the file name instead of the variable then please run the below macro and see the results
    Please put the exact file location where indicated within the code

    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: Error when trying to move a file via VBA

    Didnt Know it's on a share point.
    Ok Use this. it should work

    Please Login or Register  to view this content.
    Last edited by Kelshaer; 03-09-2012 at 10:08 AM.

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Error when trying to move a file via VBA

    Please do not quote (see the forum rules)

  10. #10
    Registered User
    Join Date
    02-20-2012
    Location
    Baltimore, MD
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Error when trying to move a file via VBA

    That worked! Thank you!
    Last edited by cg0789; 03-09-2012 at 10:17 AM.

  11. #11
    Valued Forum Contributor
    Join Date
    08-29-2011
    Location
    Mississauga, CANADA
    MS-Off Ver
    Excel 2010
    Posts
    503

    Re: Error when trying to move a file via VBA

    Does the code reside in the file that should be moved or not?
    This macro assumes that the file containing it is the same file you are trying to move.

+ 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