+ Reply to Thread
Results 1 to 8 of 8

Problem renaming files and folders

  1. #1
    Registered User
    Join Date
    03-03-2011
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    53

    Problem renaming files and folders

    I am having a problem with the NAME function and failing to understand why. I have a procedure where the user selects a folder and all the contents including subfiles are imported into column 1 of a worksheet.

    Following various conditional file changes I build a new path and file name in column 2, all well so far.

    After visually verifying the results are what I expect I want to rename the old file and folder name but I get the Filename not Found error despite the entries in column 1 never being edited or changed, what am I missing?

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Problem renaming files and folders

    Hi Orada,

    To help debug your problem try:
    Please Login or Register  to view this content.
    Also to prevent typos from ruining days and weeks of work you need 'Option Explicit' at the top of each code module.
    This forces you to declare every variable.
    http://www.cpearson.com/excel/DeclaringVariables.aspx

    Lewis

  3. #3
    Registered User
    Join Date
    03-03-2011
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Problem renaming files and folders

    Hi and thank you Lewis,

    I copied your code into a new module with the same results.

    The debug.print oldfilename and newfilename were exactly as I expected, with the addition of "Old file Name Exists = True" yet I still get the Run-time error '53': File not found on the following line
    Please Login or Register  to view this content.
    With my limited experience of file operations I simply cannot understand this, unless anyone can suggest where it is going wrong I will need to experiment more and search for possible answers again tomorrow, seems like such a simple command.

  4. #4
    Registered User
    Join Date
    03-03-2011
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Problem renaming files and folders

    Just for clarity and in case I am missing something out of ignorance the drive I am applying this to is a USB connected Hdd and the Excel version is 2007.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Problem renaming files and folders

    The old file and the new directory must exist. Name As won't create a directory, and the files must not be open.
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Registered User
    Join Date
    03-03-2011
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Problem renaming files and folders

    Thank you all for your help, stupid of me to think I could rename both the folder and file name at the same time.

    I overcome the difficulties with the code below and then similar for the file name, thanks again.

    Please Login or Register  to view this content.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Problem renaming files and folders

    You're welcome.

  8. #8
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Problem renaming files and folders

    Hi again Orada,

    Thanks for the rep points, even though shg did most of the work.

    You might find the following functions useful in the future when accessing files. The 'Exists' functions are especially useful when loop using the Dir() command, because they use 'getAttr()' which plays nicely with Dir() when Dir() is looping.

    Lewis

    Please Login or Register  to view this content.

+ 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. [SOLVED] Renaming files in infinite number of sub folders
    By BecQuack in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-26-2014, 01:23 AM
  2. Replies: 1
    Last Post: 09-12-2013, 09:23 PM
  3. Recursively Count Files in Folders and Sub-Folders
    By cdeshaz in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-01-2013, 01:15 PM
  4. Create folders and move and copy files into that folders
    By vijaybharthi in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-31-2010, 04:01 AM
  5. Renaming folders and changing links accordingly
    By fullers in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-18-2006, 08:00 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