+ Reply to Thread
Results 1 to 7 of 7

Excel VBA rename file

  1. #1
    Forum Contributor
    Join Date
    08-05-2022
    Location
    England
    MS-Off Ver
    Office 365
    Posts
    103

    Excel VBA rename file

    Hi. the below piece of code is in a spreadsheet i have which basically prompts for an xlsx file and then does a multitude of things with it. sometimes the file is .OLD extension. is there a way I can select the .OLD file and then the code renames it to .XLSX?

    Thanks


    Please Login or Register  to view this content.
    Last edited by AliGW; 04-15-2025 at 08:44 AM. Reason: Code tags added - please review the forum guidelines.

  2. #2
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,080

    Re: Excel VBA rename file

    Try:
    Please Login or Register  to view this content.

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: Excel VBA rename file

    What is the data type for fd? FileChosen?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Forum Contributor
    Join Date
    08-05-2022
    Location
    England
    MS-Off Ver
    Office 365
    Posts
    103

    Re: Excel VBA rename file

    Quote Originally Posted by ByteMarks View Post
    Try:
    Thanks very much for your reply. Much appreciated
    Last edited by 6StringJazzer; 04-23-2025 at 09:34 AM. Reason: no need to quote an entire post when replying directly to it

  5. #5
    Forum Contributor
    Join Date
    08-05-2022
    Location
    England
    MS-Off Ver
    Office 365
    Posts
    103

    Re: Excel VBA rename file

    Hi ByteMarks.

    Thanks for the code. it works well. How do I change the file back to .old when finished without being prompted to select the file again.

    i.e so select .OLD file
    file is renamed to .xlsx
    further code is processed
    originally file selected is renamed back to .old without prompting to select the file (which is now of course .xlsx)

    Thanks very much
    Last edited by 6StringJazzer; 04-23-2025 at 09:34 AM. Reason: no need to quote an entire post when replying directly to it

  6. #6
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,273

    Re: Excel VBA rename file

    There is no need to change the extension '.old' to '.xlsx' and vice versa.
    Regardless of the extension, a file created in Excel has "excel's format".
    The file extension is just information for the system about which program to associate the file with.
    Such an Excel file (with the '.old' extension) will be opened in Excel via the "File\Open" option anyway.

    For example:

    1. Standard module:
    Please Login or Register  to view this content.
    2. UserForm module:
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    08-05-2022
    Location
    England
    MS-Off Ver
    Office 365
    Posts
    103

    Re: Excel VBA rename file

    Quote Originally Posted by mjr veverka View Post
    There is no need to change the extension '.old' to '.xlsx' and vice versa.
    Regardless of the extension, a file created in Excel has "excel's format".
    The file extension is just information for the system about which program to associate the file with.
    Such an Excel file (with the '.old' extension) will be opened in Excel via the "File\Open" option anyway.

    For example:

    1. Standard module:
    Please Login or Register  to view this content.
    2. UserForm module:
    Please Login or Register  to view this content.
    Hi. You are right. I never knew you could import a file with extension .old and it still recognises it as excel format. Thanks very much

+ 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. VBA - How to rename an Excel file based on the value in a Column
    By Dhoang25 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-24-2020, 02:32 PM
  2. My File Rename Macro Always Doesn't Rename the Last Three files in the list
    By Enright in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-02-2016, 03:46 PM
  3. how multiple rename in one excel file
    By niksirat2030 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-22-2015, 07:44 AM
  4. Replies: 0
    Last Post: 01-21-2014, 10:52 AM
  5. Excel VBA find and replace string in non text file and rename file
    By razzack in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-01-2013, 02:43 PM
  6. [SOLVED] Rename Excel file name
    By Jack40 in forum Excel General
    Replies: 2
    Last Post: 09-20-2012, 05:17 AM
  7. Rename Excel File via FTP using macro
    By buczacz in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-12-2007, 04:20 PM

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