+ Reply to Thread
Results 1 to 7 of 7

user form used to rename files repeatedly adding prefix to file name

  1. #1
    Forum Contributor
    Join Date
    04-23-2012
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2013
    Posts
    116

    user form used to rename files repeatedly adding prefix to file name

    UPDATE:
    The macro seems to fail when there is a large number of files to rename (more than ~50)

    Hello,

    I have a user form that adds prefixes to file names and also has the option to subtract text from file names. This is a userform that I downloaded from a excel vba forum, and adapted to add the subtract text functionality. The userform works fine on my computer and one other computer, but the prefix function does something strange on the 3rd computer I tested this on:

    The prefix that is input repeatedly is added to the beginning of the file name. So, if I wanted to add JPM_ as a prefix, the file name would return something like JPM_JPM_JPM_JPM_JPM_JPM_JPM_JPM_JPM_file.jpg (it eventually gives an error and stops- not before adding the long prefix to the file)

    Below is the code, and attached is the workbook with userform.

    I believe what is happening is the Loop based off of tmpDIR under the "rename_files" sub is not ending and is for some reason repeating until it breaks. I was capable of adapting the code to my needs, but am not really capable of re-writing what I have , and so this problem has me stymied. Can anyone help me fix this?

    Please Login or Register  to view this content.
    test.xlsm

    Note that all three computers are running the same version of excel (2013)
    Last edited by mcdermott2; 07-09-2014 at 06:34 PM.

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

    Re: user form used to rename files repeatedly adding prefix to file name

    Try this...

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    04-23-2012
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2013
    Posts
    116

    Re: user form used to rename files repeatedly adding prefix to file name

    Thanks, AlphaFrog! Unfortunately the code you provided still leads to the same problem -- It seems I can rename up to ~35-40 files without the macro crashing, but anything beyond that and the macro loops through repeatedly until crashing

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

    Re: user form used to rename files repeatedly adding prefix to file name

    Quote Originally Posted by mcdermott2 View Post
    Thanks, AlphaFrog! Unfortunately the code you provided still leads to the same problem -- It seems I can rename up to ~35-40 files without the macro crashing, but anything beyond that and the macro loops through repeatedly until crashing
    It repeatedly adds the prefix?

    What is the error when you debug it? What line is highlighted?

  5. #5
    Forum Contributor
    Join Date
    04-23-2012
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2013
    Posts
    116

    Re: user form used to rename files repeatedly adding prefix to file name

    Run-time error '53':
    File not found

    Name curFolder & strFile As curFolder & NewName ' Rename file.

    is the highlighted line


    When I see the run-time error, the "file in directory" box updates to show the correct prefixes, but once I hit "end" or "debug" and look at the files, they have the repeated prefixes

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

    Re: user form used to rename files repeatedly adding prefix to file name

    Did you use all the code I listed?

    Is there a chance you have code versions or workbook versions mixed up?

  7. #7
    Forum Contributor
    Join Date
    04-23-2012
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2013
    Posts
    116

    Re: user form used to rename files repeatedly adding prefix to file name

    Thanks, AlphaFrog, I ended up just re-coding everything in terms that are simpler and easier for me to understand.

    I also added a function to enumerate file names.


    answer.xlsm

    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. Rename cell based on file name for multiple files
    By lmolokin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-08-2012, 05:49 PM
  2. Replies: 0
    Last Post: 08-02-2012, 03:14 PM
  3. How Can The Macro Rename Files When The Original File Name Changes Everday
    By np123345 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-01-2008, 06:59 PM
  4. [SOLVED] How do you rename Multiple files using text from a cell in the file?
    By RandyR in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-16-2005, 03:05 PM
  5. [SOLVED] Adding text file to a user form?
    By Chip in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-29-2005, 03: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