+ Reply to Thread
Results 1 to 14 of 14

Change File Names To A User Defined New Name

  1. #1
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Change File Names To A User Defined New Name

    I have attached a file. I am trying to get a code that will rename parts of a filename to a specific new filename, but KEEPING certain parts of the original file name.

    Below is a picture of the userform:

    1.png


    Below is a picture of an example of what I am trying to achieve:

    2.png

    Can you please open the attached Excel file and help me to get the code for the "Process Change" button?

    Thank you!
    Attached Files Attached Files
    If you have received help from a user, please feel free to Rep that person.
    Also, do remember to click Thread Tools and mark your thread as solved, if you have achieved a solution to your thread.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Change File Names To A User Defined New Name

    You could use this syntax
    Please Login or Register  to view this content.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Re: Change File Names To A User Defined New Name

    That does not allow keeping parts of the old file name as per the example.

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Change File Names To A User Defined New Name

    Quote Originally Posted by chin67326 View Post
    That does not allow keeping parts of the old file name as per the example.
    Why would it not? All you need to do is include the parts you want to keep in the new file name. Don't let the trees block your view of the forest.

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Change File Names To A User Defined New Name

    Think this will do the job for you.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  6. #6
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Re: Change File Names To A User Defined New Name

    Quote Originally Posted by JLGWhiz View Post
    Why would it not? All you need to do is include the parts you want to keep in the new file name. Don't let the trees block your view of the forest.
    Thanks for your reply. It is impossible to timely input the parts I want to keep in the new file name because some folders, which contain files I want to rename, have over 3,500 files in them. So it is a quite huge forest of trees.

    Therefore I am looking for a code than can take into consideration whatever I input in the "Enter Existing Text" textbox (which in the example is 'ThePowerToolsForFarmingVegetables'), and then the code should be written to keep whatever is left in that file name when it processes the renaming. For example in the first file above, '- Corner House Garage' is kept after the renaming is done. Consider the file name as split into two parts, a prefix and suffix. Essentially I want to rename the prefix but keep the suffix. In the same example above '- Corner House Garage' will be the suffix.

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Change File Names To A User Defined New Name

    Missed my post ?

  8. #8
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Re: Change File Names To A User Defined New Name

    Quote Originally Posted by bakerman2 View Post
    Missed my post ?
    Hi bakerman2, sorry the weirdest thing happened. After I typed my reply to JLGWhiz, then your post appeared. I have been testing it and it works quite good and does what I want! Thank you. However when I downloaded your version and initialized, no buttons are present on the userform and it looks like the below. No buttons appeared even after I started typing in the textboxes:

    thatimage.png

    In design mode however I note you combined the select folder button and process change button into a single button. Is it possible to have the two buttons separate as per the original image above? i.e. a command button to select a folder, then I will enter the details in the two textboxes, after which I will click the process change button (i.e. command button 2).

    Thanks!

  9. #9
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Re: Change File Names To A User Defined New Name

    Quote Originally Posted by chin67326 View Post
    Hi bakerman2, sorry the weirdest thing happened. After I typed my reply to JLGWhiz, then your post appeared. I have been testing it and it works quite good and does what I want! Thank you. However when I downloaded your version and initialized, no buttons are present on the userform and it looks like the below. No buttons appeared even after I started typing in the textboxes:

    Attachment 603965

    In design mode however I note you combined the select folder button and process change button into a single button. Is it possible to have the two buttons separate as per the original image above? i.e. a command button to select a folder, then I will enter the details in the two textboxes, after which I will click the process change button (i.e. command button 2).

    Thanks!
    bakerman2 , nevermind, I did some tweaks to your code and have what I want. Thanks again; you have been repped.

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Change File Names To A User Defined New Name

    I wrote it this way to make sure both textboxes are filled before starting the code.
    But tweaking it to your liking is of course your prerogative.

    Anyway, glad to help and thanks for rep+.

  11. #11
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Re: Change File Names To A User Defined New Name

    Quote Originally Posted by bakerman2 View Post
    I wrote it this way to make sure both textboxes are filled before starting the code.
    But tweaking it to your liking is of course your prerogative.

    Anyway, glad to help and thanks for rep+.
    Sure no worries.

    You are welcome and thanks again

  12. #12
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Re: Change File Names To A User Defined New Name

    Hi bakerman2, I would like to ask for your assistance rather than starting a new thread. I forgot to mention that some of the filenames that will be renamed contain Chinese characters and when I run the code I get the below run-time error 52/debug error. I believe Chinese characters are Unicode? Is there a tweak that you can do to your code that can tell the code to ignore or avoid the Chinese characters but still execute the renaming process? Maybe a tweak that can ignore the debug error?

    By the way, the Chinese characters will be inputted in Textbox 1 ('Enter Existing Text' textbox) and there will be no Chinese characters in the remainder of the filename that we will be keeping.

    I would be keen to know what you can do in this scenario.


    31.12.181.png

    Thanks!

  13. #13
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Re: Change File Names To A User Defined New Name

    Any clue how to fix the above?

  14. #14
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    213

    Re: Change File Names To A User Defined New Name

    I did some searching and found the below code. I think I need a function inputted that can eliminate all non-alphanumeric characters from the filenames. However I do not know how to integrate the below in the code. Any clue anyone?

    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] How to refer checkbox with user defined names
    By pankajy18 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-04-2013, 07:05 AM
  2. Importing a data from a text file - user-defined file
    By DaveSev in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-01-2013, 07:02 PM
  3. [SOLVED] Call command buttons by user-defined names
    By Willardio in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-14-2013, 10:58 AM
  4. Replies: 0
    Last Post: 11-19-2012, 10:41 AM
  5. VBA: Import CSV file into an Excel Workbook with user defined file name and directory
    By LarryLegend in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-18-2012, 04:47 AM
  6. Help creating Summary Page w/ user defined sheet names
    By gophil1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-31-2012, 07:35 AM
  7. Replies: 0
    Last Post: 12-14-2011, 02:28 PM
  8. User defined function - adding names
    By chillihawk in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-01-2006, 03: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