+ Reply to Thread
Results 1 to 13 of 13

Macro to convert Xls file format to Xlsx

  1. #1
    Forum Contributor meus's Avatar
    Join Date
    11-25-2014
    Location
    kathmandu
    MS-Off Ver
    2010/ 2013
    Posts
    287

    Angry Macro to convert Xls file format to Xlsx

    Hi Friends!!

    I am searching for the macro which can convert all the Xls file to Xlsx from a specified Folder. However i am unable to find the correct macro..
    i have written a below code but don't know whats wrong.. Can someone help me on this please?

    Please Login or Register  to view this content.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Macro to convert Xls file format to Xlsx

    You can't just change the name; well, maybe you can, but it won't change the file structure ... and, if it does work, Excel will probably complain that the file doesn't have the expected file structure.

    You need to use SaveAs and use the new file name and choose the appropriate file type. After you have converted and checked the files, you can delete or (better) archive the original files.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor meus's Avatar
    Join Date
    11-25-2014
    Location
    kathmandu
    MS-Off Ver
    2010/ 2013
    Posts
    287

    Re: Macro to convert Xls file format to Xlsx

    Thanks for that.. But i have Thousands of file thats why i needed a macro...It will consume much time if i do manually..
    Are you sure that its not possible??
    Thanks

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Macro to convert Xls file format to Xlsx

    You misunderstand. You can do exactly what you are doing but, instead of just trying to change the file extension, you need to use SaveAs to change the name AND the file structure/type (to .xlsx)

    Regards, TMS

  5. #5
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Macro to convert Xls file format to Xlsx

    Hey meus

    I think I have what you're looking for. I thought that was a good idea & have a use for it myself.
    This code will change from one file format to another.
    There's a fuller explanation in the attached workbook
    I'd like to say it took me 5 minutes, but I'd be lying
    Have fun

    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Macro to convert Xls file format to Xlsx

    I've improved the previous code a little bit by adding a DoEvents. My computer was not responding every now & then & the DoEvents has speeded things up.
    I got the counter to count the right amount of files processed & if there's an error during one of the conversions, the message box tells you the name of the file that caused it.

    TMS: Thanks for the rep & the comment

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor meus's Avatar
    Join Date
    11-25-2014
    Location
    kathmandu
    MS-Off Ver
    2010/ 2013
    Posts
    287

    Re: Macro to convert Xls file format to Xlsx

    Hey!! thanks Philb1
    Added Rep
    can you explain me little bit about the following?
    Please Login or Register  to view this content.
    thanks

  8. #8
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Macro to convert Xls file format to Xlsx

    Hi meus.. Thanks for the rep.

    The case function is used to find the file format number of the file extension you want to convert to. In your case as you're converting to xlsx, it will find 51. So the variable Num has a value of 51

    Then
    Please Login or Register  to view this content.
    will save the workbook to the destination folder with a xlsx file extension
    You can save to any of the file formats. Have a play
    Cheers
    Phil

  9. #9
    Forum Contributor meus's Avatar
    Join Date
    11-25-2014
    Location
    kathmandu
    MS-Off Ver
    2010/ 2013
    Posts
    287

    Re: Macro to convert Xls file format to Xlsx

    Hey Phil, one more thing...
    It works perfectly great in my computer, excel 2013..
    But in my friends computer, i tried with excel 2007.. the file is converted but with no extension...
    What can be the problem?
    Thanks,...

  10. #10
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Macro to convert Xls file format to Xlsx

    I'm using Excel 2010 & it works fine here too. As for 2007 I don't know & I don't know anyone who has it so I can try to replicate what's happening.
    I've been excelling for about 3 years & I've never used an older version of Excel. Maybe someone who has 2007 can help.
    Sorry I can't be of more help

  11. #11
    Forum Contributor meus's Avatar
    Join Date
    11-25-2014
    Location
    kathmandu
    MS-Off Ver
    2010/ 2013
    Posts
    287

    Re: Macro to convert Xls file format to Xlsx

    Thank you Phil...
    Really appretiate your help...

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Macro to convert Xls file format to Xlsx

    Is your 2007 machine set up to not show file extensions?

  13. #13
    Forum Contributor meus's Avatar
    Join Date
    11-25-2014
    Location
    kathmandu
    MS-Off Ver
    2010/ 2013
    Posts
    287

    Re: Macro to convert Xls file format to Xlsx

    No... it shows up the file extensions...

+ 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] convert xlsx to csv and save to file directory
    By shaz0503 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-27-2014, 07:19 PM
  2. Convert a TXT in XLSX or XLSB without opening the file (VBA)
    By mortphil in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-20-2014, 08:27 AM
  3. convert .iqy file to .xlsx file using macro
    By gourishjoshi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-10-2013, 02:51 PM
  4. Replies: 4
    Last Post: 10-23-2013, 12:54 AM
  5. How to convert a file to xlsx
    By Raner in forum Excel General
    Replies: 2
    Last Post: 12-15-2011, 03:27 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