ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   QueryTable Basics.. (https://www.excelbanter.com/excel-programming/355562-querytable-basics.html)

thiaga

QueryTable Basics..
 
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



All times are GMT +1. The time now is 08:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com