I would like to have macros that will run .sql scripts (that are saved in a folder), instead of having to put the SQL code in the Excel VBA script.
I have over 50 scripts that I'd like to automate - and these have many queries in each that are separated by a ;
I've tried
db.ExecuteImmediate ("\\c\sql_folder\1.0_Create_My Lovely_Table.sql")
but the error says 'Object Required'
The code below works but I'd like help to do the above. Thanks.
Sub CREATE_My_lovely_table()
Dim con As ADODB.Connection
Dim recset As ADODB.Recordset
Dim ConnectionString As String
Dim SQL_String As String
Set con = New ADODB.Connection
Set recset = New ADODB.Recordset
ConnectionString = "xxxxxx.1;User ID=XXXX_XXXX_XXXX;password=xxxxxxxx;Data Source=xxxxxxxx"
con.Open ConnectionString
SQL_String = "CREATE TABLE My_lovely_table (CASEID NUMBER,ACCOUNTNUMBER NUMBER,RESOLVEDDATE TIMESTAMP,RESOLUTION VARCHAR (50),RESOLVEDBY VARCHAR (100),ORDERID NUMBER)"
recset.Open SQL_String, con
con.Close
End Sub