-1

I would like to know if there is any VBA code which allows me to execute .sql files by clicking a button in Excel?

I've been surfing different webs, but all of them showed code which consists into write the SQL query in the macro, despite it isn't what I wanted. So I have stored .sql scripts as files in different folders on my computer and what I want is to run this script by clicking a button in Excel using VBA.

1 Answer 1

0

Short answer is no. There is no magic button in Excel that does that. Easiest that I can think of is run/import that .sql to MySQL, SQL Server, Postgres, etc. to become a database. Example using MS SQL Server:

How do I import a .sql data file into SQL Server?

Once you run successfully that .sql into a DBMS, you may use built-in tools of that DBMS to export the tables into Excel. See the link below as an example:

How to Import and Export SQL Server data to an Excel file

It may not be as easy as pressing a button but not as tedious as hardcoding it. I hope it helps.

Sign up to request clarification or add additional context in comments.

1 Comment

Hey, thanks a lot for your answer! Indeed, I have created these scripts in SQL Server and as I have to execute some codes in VBA which update this databases. I wanted to find this code to open those .sql files and run them. I know you have for instance the VBA code "Do.Cmd.OpenQuery" to open Access db and run any query save in this Access db.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.