QueryTable Basics..

T

thiaga

I am trying to assign a range of cells to a query table.
But am not able to do it..
The data is in a Sheet called "MasterData" not sure where to specify
that..
Also when i run the query, is it possible to get the data (In an array
or RecordSet) and do some formatting before it is displayed...

The below code returns a 1004 error..not sure why..

Thanks in Anticipation
Thiaga

Public Sub test21()
Dim dbqPath As String
Dim qtb As QueryTable
Const qtbName As String = "MyQueryTable"
Const strCnn As String = "ODBC;Driver={Microsoft Excel
Driver(*.xls)};DriverId=790;"
Dim strSQL As String
Dim targetSh As Worksheet

strSQL = "SELECT * FROM MyQueryTable"
dbqPath = ThisWorkbook.FullName
Set targetSh = ThisWorkbook.Sheets("Work Effort Summary")
Set rng = targetSh.Range("B15")
With targetSh
With .QueryTables.Add(Connection:=strCnn & "DBQ=" & dbqPath &
";", _
Destination:=rng, Sql:=strSQL)
.Name = qtbName
.FieldNames = True
.Refresh
End With
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top