ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Creating QueryTable from VB6 (https://www.excelbanter.com/excel-programming/345588-re-creating-querytable-vb6.html)

Jake Marx[_3_]

Creating QueryTable from VB6
 
Hi Jace,

I think you may be running into an unqualified reference error, but it's
hard to tell without seeing all the code (and that oh-so-helpful error
displayed by VB <g). See if this works:

With oXL.ActiveSheet
With .QueryTables.Add(connection:=gConnect, _
Destination:=.Range("A5"), sql:=sql$)
.Refresh
End With
End With

Notice the dot in front of Range("A5") - this way, you're explicitly telling
Excel that the range lives on the active sheet.

--
Regards,

Jake Marx
www.longhead.com


[please keep replies in the newsgroup - email address unmonitored]

Jace wrote:
Hi,

I am trying to create an Excel addin that retrieves query statements
from a report generator and loads them as querytables in the active
worksheet. The problem I am having is when I try to execute the
QueryTables.Add method.

I have declared oXL as an object and instantiated it with

Set oXL = Application

When I execute this code...

With oXL.ActiveSheet.QueryTables.Add(connection:=gConne ct,
Destination:=Range("A5"), sql:=sql$)
.Refresh
End With

I get an error message that says "Method '~' of Object '~' failed."

The same syntax works fine if I try this from VBA, but not within my
VB6 Addin. Any ideas as to what I am doing wrong?

Thanks





All times are GMT +1. The time now is 05:34 PM.

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