+ Reply to Thread
Results 1 to 19 of 19

Rename a special filename

  1. #1
    Registered User
    Join Date
    07-07-2014
    Location
    the Netherlands
    MS-Off Ver
    2016
    Posts
    56

    Rename a special filename

    I have a file with filename: 20151231-  Newyear -12471010.html
    A hyperlink to this file looks like: 20151231-%25F0%259F%258E%2587 Newyear %25F0%259F%258E%2587-12471010.html

    Now I want to rename this file. I tried:

    Please Login or Register  to view this content.
    But this fails , possible due to the fact that Filename becomes: 20151231- ?? Newyear ?? 12471010.html

    How to solve this problem?

    With kind regards

    Jan Lichtenbelt

    PS. Now with code tags. The question remains the same
    Last edited by Jan Lichtenbelt; 02-25-2016 at 03:10 PM.

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

    Re: Rename a special filename

    Please take a few minutes to re-read the forum rules, and then edit your post to add CODE tags.

    Thanks.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Rename a special filename

    First, you need to use fullpath name in the code, something like this:
    Please Login or Register  to view this content.
    But it still don't solve the symbolic character problem. The code stops at;
    Please Login or Register  to view this content.
    I don't know how to resolve that.
    I suggest you use a freeware called 'Advanced Renamer'. It can do batch renaming using list (oldname-newname) or pattern.

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

    Re: Rename a special filename

    I recollect that Dir returns filenames with Unicode characters converted to ANSI, which means you can't use the resulting string to open (or rename) the file. VB includes a DirW function to accommodate this, but not VBA.

    You need to use instead the FileSystemObject object.

  5. #5
    Registered User
    Join Date
    07-07-2014
    Location
    the Netherlands
    MS-Off Ver
    2016
    Posts
    56

    Re: Rename a special filename

    The Dir() function and FileSytemObect give the same result. As long as you put the result of the dir() function of of the objFile.Name directly in a cell, you get the original files name. But as sson as you put the result in a string, the uncides are olst. See picture

    Added Febr 28-2016 the code as requested:
    Please Login or Register  to view this content.
    The picture show additional an output to the cell( 25,2) and I=I just for stopping the process.
    Attached Images Attached Images
    Last edited by Jan Lichtenbelt; 02-28-2016 at 09:46 AM.

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

    Re: Rename a special filename

    Right, but the objective is to rename the file, right? So if you can identify it, you can rename it.

  7. #7
    Registered User
    Join Date
    07-07-2014
    Location
    the Netherlands
    MS-Off Ver
    2016
    Posts
    56

    Re: Rename a special filename

    Rename the file depends on its original name. How do I check I rename the correct file? Then I have to check if (part of) the file name is correct. That means I have to save the filename in a string. And then information is lost, see above.

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

    Re: Rename a special filename

    What part of the name identifies it as the file of interest?

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    07-07-2014
    Location
    the Netherlands
    MS-Off Ver
    2016
    Posts
    56

    Re: Rename a special filename

    The part of interest is between the first and the last - (dash/minus sign)

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

    Re: Rename a special filename

    The Unicode characters are necessary to distinguish the filename?

  11. #11
    Registered User
    Join Date
    07-07-2014
    Location
    the Netherlands
    MS-Off Ver
    2016
    Posts
    56

    Re: Rename a special filename

    In general, the unicodes are not essential to recognise the filename

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

    Re: Rename a special filename

    Right. So the presence of what ANSI string is necessary to distinguish the filename?

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    07-07-2014
    Location
    the Netherlands
    MS-Off Ver
    2016
    Posts
    56

    Re: Rename a special filename

    Any string present between the first and the last - (dash/minus sign)
    Remark: It is not one example. For one file I can do it myself without VBA Excel. But I want a general program to select files and rename it, depending on the filename. A priori I do not know what the string is, I only know it is between de outerst dashes.

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

    Re: Rename a special filename

    I'm losing the bubble.

    I only know it is between de outerst dashes.
    Please Login or Register  to view this content.
    That's anything with two dashes in the filename.

  15. #15
    Registered User
    Join Date
    07-07-2014
    Location
    the Netherlands
    MS-Off Ver
    2016
    Posts
    56

    Re: Rename a special filename

    Dear shg

    Thanks a lot. It works!

    With kind regards

    Jan Lichtenbelt

  16. #16
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: Rename a special filename

    @ Jan Lichtenbelt ,
    Hello Jan,
    Would it be possible to post the code from Post # 5 in Code Tags?
    That code could be useful to me just now
    Thanks, Danke
    Alan
    Germany
    '_- Google first, like this _ site:ExcelForum.com Gamut
    Use Code Tags: Highlight code; click on the # icon above,
    Post screenshots COPYABLE to a Spredsheet; NOT IMAGES PLEASE
    http://www.excelforum.com/the-water-...ml#post4109080
    https://app.box.com/s/gjpa8mk8ko4vkwcke3ig2w8z2wkfvrtv
    http://excelmatters.com/excel-forums/ ( Scrolll down to bottom )

  17. #17
    Registered User
    Join Date
    07-07-2014
    Location
    the Netherlands
    MS-Off Ver
    2016
    Posts
    56

    Re: Rename a special filename

    Dear Alan,

    I put it on the forum.

    Met vriendelijke groeten

    Jan

  18. #18
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: Rename a special filename

    Thanks Jan,

    MFGruß aus Hof !

    Alan

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

    Re: Rename a special filename

    You're welcome.

+ 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] Copy a sheet, rename it by value in range then export product to new workbook and rename
    By MagicMan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-31-2015, 07:24 PM
  2. [SOLVED] Input Filename to copy, rename and save to directory
    By Tellm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-04-2014, 05:58 AM
  3. [SOLVED] Runtime 1004 after prompting for filename but not when filename hard coded.
    By cgoodenough in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-04-2013, 03:46 AM
  4. Replies: 2
    Last Post: 11-21-2013, 02:43 PM
  5. Copy Single Sheet From Multiple Books And Rename Using Source Filename
    By DeRo22 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-16-2013, 12:09 PM
  6. Remove number and special characters from Filename
    By Elmholt in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-30-2012, 06:53 PM
  7. [SOLVED] To rename a workbook filename with the column value of a worksheet.
    By Vinutha in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 10-18-2012, 04:29 AM

Tags for this Thread

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