Conquering SaveAs in VBA - Saving in Multiple File Formats - CODE and Download Included

Поділитися
Вставка
  • Опубліковано 15 лют 2021
  • Conquering SaveAs in VBA - File Formats
    **Get the Excel file here
    chrisjterrell.com/blog/225109...
    **Grab the Free VBA Quick Reference Guide
    www.chrisjterrell.com/excel-v...
    This video explores best practices and hopes to shed light on some issues you will run into when using the SaveAs Method in VBA.
    All the Excel SaveAs FileFormats are found here docs.microsoft.com/en-us/offi...
    Digging deeper into "SaveAs" will uncover some annoying workarounds when saving a file in a different file format.
    In the first section of the code, we use the "Thisworkbook.FullName" property to get the file path as a string. This string is the location where we will save the file. Next, we turn off alerts using "Application.DisplayAlerts = False". By adding this line of code, we allow Excel to Save our file over the existing file with no problem and no warnings. To complete the basic save as we use Activeworkbook.SaveAs and add the file path we got from the "FullName" property. The easy work is complete.
    In the next section, we drill into what Excel needs to save a file, the file format, and what Windows needs to reference the correct application to open the file format. In other words, Excel will save the file in a format that Excel can read, and Windows needs the appropriate file extension to make sure it is using the correct file format. In the next line of code, we will show how Windows only cares about the last extension. A file with the name "MyExcelFile.xlsm.csv" will be considered a CSV file by Windows.
    At this point, we could have easily saved all the files and file types by adding the correct extensions and file formats, and we would have been successful with terribly named files. To avoid this, we use a file scripting object to identify the extension and remove it from the string we are using as the file path destination. We add the correct extension to the string and add the correct file type, and the files save as we expect, like magic. Now pat yourself on the back because you have conquered the challenge of Fileformats when using SaveAs in Excel VBA. You can save a file as the following extensions (xls,xlsx,xlsb,xlsm, and csv)

КОМЕНТАРІ • 10

  • @doriginal69
    @doriginal69 2 роки тому +2

    Finally somebody did this....thanks!

  • @evanimtiaz7716
    @evanimtiaz7716 3 роки тому +1

    your videos saved me on my midterm thank you

  • @XShollaj
    @XShollaj 3 роки тому +1

    Surprised you dont have more subscribers! Great content

  • @datascientistoflife8550
    @datascientistoflife8550 2 роки тому +1

    Thanks man for posting video that what i am looking for..savs as with file type..typically xlsm

  • @djmixerbox
    @djmixerbox Рік тому

    Thank you!!!

  • @danushairan
    @danushairan 2 роки тому

    Question:
    I make multiple CSV with VBA and the code works perfectly with one issue.
    My CSV should be in semicolon and comma as a decimal delimiter but! CSV created by VBA is always comma as column separator and dot as decimal separator.
    Does anybody know how you can change that in VBA?