0

I want to load specific data(query) from Oracle database into excel. I am able to achieve it through external connections, (Mircosoft Data Access - OLE DB Provider for Oracle), but all of the table is loaded. This was by hit and try. I am not aware what OLE DB is.

  1. Is it possible to load specific data using that method.
  2. How can I load the same from VBA, I have read many sources, blogs but none are lucid and comprehensive. Can somebody please explain for a newbie. Or refer to me some book/source.
4
  • Have you tried using ADODB objects?
    – Amen Jlili
    Commented Jan 27, 2015 at 13:47
  • I am not very well aware what ADODB is, I cannot use any external libraries for the same. It's for a office environment.
    – garg10may
    Commented Jan 27, 2015 at 13:49
  • ADODB is included in VBA. You can add it as a reference from your Tools menu in your VBA editor. It's called Microsoft ActiveX Data Objects 2.8.
    – Amen Jlili
    Commented Jan 27, 2015 at 13:51
  • Ok, I can do that, I remember this was suggested somewhere but after that details got shoddy, how do I progress after that. ?
    – garg10may
    Commented Jan 27, 2015 at 13:53

1 Answer 1

1

This function will connect to an Oracle Database using ADODB. Make sure to include Microsoft ActiveX Data Objects 2.8 as a reference. You can configure the connectingstring to suit your needs if there are admin privileges.

It will store your database into a variant.

Function ConToDataBase(DBPath As String) As Variant
Dim Con As ADODB.Connection
Dim Rs As ADODB.Recordset
Dim SQL As String
SQL = "SELECT * FROM TableName"
Set Con = New ADODB.Connection
With Con
.ConnectionString = "Provider=OraOLEDB.Oracle;Data source=" & DBPath & ";UserID=;Password:=;"
.Open
End With
Set Rs = New ADODB.Recordset
Rs.Open SQL, Con
Dim Var As Variant
Var = Rs.GetRows
ConToDataBase = Var
Set Rs = Nothing
Con.Close
End Function
3
  • Deja Vu, where do I put username, password, database name. How is it actually working. ? How can I print that data as a table as viewed in database.
    – garg10may
    Commented Jan 27, 2015 at 14:07
  • Added the userID and the Password to the connecting string. As for the database you simply pass its path as the argument of the function.
    – Amen Jlili
    Commented Jan 27, 2015 at 14:11
  • Ok I added database name, username, password. won't it need any other details. I haven't worked with VBA. My purpose is same get data like the graphic utility but not all the data.
    – garg10may
    Commented Jan 27, 2015 at 14:23

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.