filmov
tv
Conquering SaveAs in VBA - Saving in Multiple File Formats - CODE and Download Included
Показать описание
Conquering SaveAs in VBA - File Formats
**Get the Excel file here
**Grab the Free VBA Quick Reference Guide
This video explores best practices and hopes to shed light on some issues you will run into when using the SaveAs Method in VBA.
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.
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)
**Get the Excel file here
**Grab the Free VBA Quick Reference Guide
This video explores best practices and hopes to shed light on some issues you will run into when using the SaveAs Method in VBA.
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.
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)
Комментарии