VBA Code to Change File Extension

Change File Extension using VBA Code (with Images)

What is it:

This VBA code will help you change file extension of the files in a particular folder/directory.

For eg. If you want to change the extension of the Excel files received in .xlsx to .xls or visaversa then this VBA code can be used.


If you are working on project where you get input files with different file extensions where in you want the files in a standard format for your VBA program to work and you don’t have any control over the input files then this peace of code will be very helpful as you can change extension to any format you want.

Windows Script object is used to change the extension in this code.

How to Change File Extension using VBA code:

Step 1: Open the workbook that need to be protected and press Alt + F11

Step 2: Copy and Paste the below code in the VBA editor window and Save the workbook.

Sub changeExt()

strDir = “C:\myFolder\” ‘mention your files folder path here

With CreateObject(“wscript.shell”)

   .currentdirectory = strDir

   .Run “%comspec% /c ren *.xlsx *.xls”, 0, True

End With

End Sub

Step 3: Click F5 to run the code.

change file extension


About Anson

I’m Anson having a decade of versatile experience in Business Process Outsourcing, Finance & Accounting, Information Technology, Operational Excellence & Business Intelligence. I have got the opportunity to work for Genpact, Hewlett Packard, M*Modal and Capgemini in various roles and responsibilities, starting from an Associate to a Manager. Learning anything new has always been my passion and if related to Business and Technology then I love it. asKeygeek.com is an outcome of my passion towards the same and I have been into asKeygeek since 2012. Outside business and technology I’m a movie buff who spends hours together watching and learning Cinema, I do make Short Films 🙂


  1. what if… the files had no extensions to begin with.. and you want them all to add .xls?

  2. Good day
    How to change specific File extention ?
    Because this code change all files in folder


  3. Pingback: Change File Extension using VBA (with Images) |...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.