Excel VBA connect to remote Oracle DB with InstantClient Excel VBA connect to remote Oracle DB with InstantClient oracle oracle

Excel VBA connect to remote Oracle DB with InstantClient


Ended up editing/using this function (which does not(?) use driver/provider: InstantClient but still uses the files):

Function ORAQUERY(strHost As String, strDatabase As String, strSQL As String, strUser As String, strPassword As String)  Dim strConOracle, oConOracle, oRsOracle  Dim StrResult As String  StrResult = ""  strConOracle = "Driver={Microsoft ODBC for Oracle}; " & _         "CONNECTSTRING=(DESCRIPTION=" & _         "(ADDRESS=(PROTOCOL=TCP)" & _         "(HOST=" & strHost & ")(PORT=1521))" & _         "(CONNECT_DATA=(SERVICE_NAME=" & strDatabase & "))); uid=" & strUser & " ;pwd=" & strPassword & ";"  Set oConOracle = CreateObject("ADODB.Connection")  Set oRsOracle = CreateObject("ADODB.Recordset")  oConOracle.Open strConOracle  Set oRsOracle = oConOracle.Execute(strSQL)  MsgBox (oRsOracle.Fields(0).Value)  varResult = oRsOracle.GetRows  Do While Not oRsOracle.EOF      If StrResult <> "" Then        StrResult = StrResult & Chr(10) & oRsOracle.Fields(0).Value      Else        StrResult = oRsOracle.Fields(0).Value      End If    oRsOracle.MoveNext  Loop  oConOracle.Close  Set oRsOracle = Nothing  Set oConOracle = Nothing  ORAQUERY = StrResultEnd Function



Correct full Connection String:

Driver={Microsoft ODBC for Oracle}; CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=strHost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=strDatabase))); uid=strUser; pwd=strPassword;

Provider or Driver:
{Microsoft ODBC for Oracle}

Needed to set PATH environmental variable to point to instantclient.
Didn't use any of the other environmental variables e.g. ORACLE_HOME, TNS_ADMIN, etc.