

You can do tons of great things with ADODB / MS Queries / SQL in Excel. This is actually quite an important step as if you VBA code is runs a lot of queries or computations you might see a slow-down soon enough! Lastly we need to Clean up our Objects to free memory. Loop Until rs.EOF 'Have we reached End of RecordSet 'Loop through records - rs(0) - first column, rs(1) - second column etc. We need to loop through the recordset to get each record:

The Execute command returns a ADODB RecordSet. We can obviously extend this query just to filter people above the age of 30: What does it do? It indicates that our records are in Sheet1. So what happens here? First we run the Execute command with our SELECT query: Having connected to our Data Source Excel Worksheet we can now run a SQL SELECT Query: As well as our own IP (Achtung Cthulhu), Modiphius publishes tabletop games based on major licensed properties including Conan, Dune, the Elder Scrolls Call To Arms, Fallout The Roleplaying Game & Fallout Wasteland Warfare, Star Trek Adventures, and many more.
#Call to arms mod vb driver#
This is the same Driver which runs SQL Queries on MS Access Databases: So what is happening in the macro above? Let us break it down: Connecting to the Data Sourceįirst we need to connect via the ADODB Driver to our Excel Worksheet. ConnectionString = "Data Source=" & ThisWorkbook.Path & "\" & ThisWorkbook.Name & " " & "Extended Properties=""Excel 12.0 Xml HDR=YES"" "

Set cn = CreateObject("ADODB.Connection") The VBA Code is below: Sub RunSELECT()ĭim cn As Object, rs As Object, output As String, sql as String On the right see my Excel Worksheet and the Message Box with the similar output from my VBA Macro.
#Call to arms mod vb how to#
Let see how to run a simple SELECT SQL Query in Excel VBA on an example Excel Worksheet. Want to learn how to create a MS Query manually? See my MS Query Tutorial Using SQL in VBA example Want to create SQL Queries directly from Excel instead? See my Excel SQL AddIn
