I have a manual process in SQL Server that I would like to automate in Excel VBA. In MS SQL Server 2014, the task is to upload a csv file to a new table in a database. To do this, I right-click on the database that I want, click Tasks / Data Import. This opens up the SQL Server Import and Export Wizard. In there, I choose Flat File Source as the Data Source. Then, I choose the csv file that I want. I tick the checkbox, “Column names in the first data row”. I click next, next and the file creates on the server.
Is there a way to do this from Excel VBA? I’m sure I can create the table in SQL from Excel VBA by passing across a CREATE TABLE command, and then execute a BULK INSERT command, which will pass the data across. However, I’d rather avoid the creation of the table as it would involve specifying the data types of the columns; when the process is invoked from SQL Server, SQL Server does that for you automatically. Can I also do that automatically from Excel VBA?