1.) Two ways you can go, change the SQL so the headers are provided. Example: Say the field name was "Foo" but you wanted the header of "Bar". You could do :1B.) You could also just hardcode the headers in the worksheet and just not pull in the field names:SELECT MyTable.Foo as Bar, MyTable.MyField2, MyTable.MyField3 FROM MyTable
2.) Yes you will need to update strConnection to be a valid connection string for your Oracle database.Option Explicit Public Sub Example() Const strSQL_c As String = _ "SELECT * From Customers " & _ "WHERE Country = 'UK' " & _ "ORDER BY CompanyName;" Dim strConnection As String Dim strDBPath As String strConnection = _ "ODBC;DSN=MS Access Database;DBQ=" & _ "C:\Program Files\Microsoft Office\OFFICE11\SAMPLES\Northwind.mdb;" QueryDB strConnection, Sheet1.Cells(2, 1), strSQL_c End Sub Public Sub QueryDB(ByVal connectionString As String, ByVal target As _ Excel.Range, ByVal SQL As String) Dim qt As Excel.QueryTable Dim ws As Excel.Worksheet Set ws = target.Parent Set qt = ws.QueryTables.Add(connectionString, target, SQL) qt.FieldNames = False qt.Refresh BackgroundQuery:=False End Sub






Reply With Quote