Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Dynamic Web Queries

Hello,

I am attempting to use the below code to run some web queries via my macro.
I am often times getting an Application defined or Object defined error on
the .Refresh BackgroundQuery part. I have about 5 of these queries in my
macro and the error can happen in any of them and there does not appear to
be a pattern. I dont know if the program is having problems connecting to
the online information or what might be causing this, but I have had
multiple web queries run through a macro and have never received this error.
I tried tossing some Application.wait code in there but that did not seem to
help. Does anyone have any suggestions on this?

Also, as I run this macro over and over (I need to run it each day to gather
data) "ExternalData_x" items are being created with respect to these web
queries. To explain this further you can see this under the Insert - Name -
Define menu. I can delete these manually but would prefer that they arent
saved at all in the spreadsheet if this is at all detrimental. I have the
macro deleting the QueryTables with Selection.QueryTable.Delete, but these
ExternalData_x. Any suggestions on this?

Thanks

Matt

With Sheets("RawData").QueryTables.Add(Connection:="URL ;" & url, _
Destination:=Sheets("RawData").Range("b2"))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = False
End With


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Dynamic Web Queries

If you analyze your code, you will realize that each time it is
executed you are adding a new query ...QueryTables.Add(...

Instead, turn on the macro recorder (Tools | Macro Record new
macro...), refresh an existing query, and turn off the recorder. XL
will give you the necessary code to reuse an existing query. It should
be something like:

Range("B2").Select
Selection.QueryTable.Refresh BackgroundQuery:=False

which can be modified to

Range("B2").QueryTable.Refresh BackgroundQuery:=False


--
Regards,

Tushar Mehta, MS MVP -- Excel
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article , fourstar77
@hotmail.com says...
Hello,

I am attempting to use the below code to run some web queries via my macro.
I am often times getting an Application defined or Object defined error on
the .Refresh BackgroundQuery part. I have about 5 of these queries in my
macro and the error can happen in any of them and there does not appear to
be a pattern. I dont know if the program is having problems connecting to
the online information or what might be causing this, but I have had
multiple web queries run through a macro and have never received this error.
I tried tossing some Application.wait code in there but that did not seem to
help. Does anyone have any suggestions on this?

Also, as I run this macro over and over (I need to run it each day to gather
data) "ExternalData_x" items are being created with respect to these web
queries. To explain this further you can see this under the Insert - Name -
Define menu. I can delete these manually but would prefer that they arent
saved at all in the spreadsheet if this is at all detrimental. I have the
macro deleting the QueryTables with Selection.QueryTable.Delete, but these
ExternalData_x. Any suggestions on this?

Thanks

Matt

With Sheets("RawData").QueryTables.Add(Connection:="URL ;" & url, _
Destination:=Sheets("RawData").Range("b2"))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = False
End With



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Dynamic Web Queries

Thank you for looking at my problem. I understand what you are saying, but I
require the ability to change the query through the code, therefore I often
times need to be able to add a new query. But when I do this, I have no need
for the old query although the old queries seem to remain in the
spreadsheet.

Now, I have modified my code so that it no longer requires 5 queries, rather
just 1. But, even with your suggestion below and simplifying the code, I am
often times getting an Application defined error when the code attempts to
refresh the query. It does not happen every time. I just dont understand why
the refresh is not working all the time as I have used the refresh command
in other spreadsheets. Could it have to do with multiple queries existing
for the same cell due to the QuerTables.Add function or something along
those lines? Or could the web query be timing out and not getting all of the
data?

Basically the code seems to be running great except for this Application
defined or Object defined error with respect to refreshing the query. Any
further assistance that anyone can provide would be wonderful.

Thanks again for all the help Tushar!

Matt Day

"Tushar Mehta" wrote in message
news:MPG.1a7c288da59dea7b98968e@news-server...
If you analyze your code, you will realize that each time it is
executed you are adding a new query ...QueryTables.Add(...

Instead, turn on the macro recorder (Tools | Macro Record new
macro...), refresh an existing query, and turn off the recorder. XL
will give you the necessary code to reuse an existing query. It should
be something like:

Range("B2").Select
Selection.QueryTable.Refresh BackgroundQuery:=False

which can be modified to

Range("B2").QueryTable.Refresh BackgroundQuery:=False


--
Regards,

Tushar Mehta, MS MVP -- Excel
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article , fourstar77
@hotmail.com says...
Hello,

I am attempting to use the below code to run some web queries via my

macro.
I am often times getting an Application defined or Object defined error

on
the .Refresh BackgroundQuery part. I have about 5 of these queries in my
macro and the error can happen in any of them and there does not appear

to
be a pattern. I dont know if the program is having problems connecting

to
the online information or what might be causing this, but I have had
multiple web queries run through a macro and have never received this

error.
I tried tossing some Application.wait code in there but that did not

seem to
help. Does anyone have any suggestions on this?

Also, as I run this macro over and over (I need to run it each day to

gather
data) "ExternalData_x" items are being created with respect to these web
queries. To explain this further you can see this under the Insert -

Name -
Define menu. I can delete these manually but would prefer that they

arent
saved at all in the spreadsheet if this is at all detrimental. I have

the
macro deleting the QueryTables with Selection.QueryTable.Delete, but

these
ExternalData_x. Any suggestions on this?

Thanks

Matt

With Sheets("RawData").QueryTables.Add(Connection:="URL ;" & url, _
Destination:=Sheets("RawData").Range("b2"))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = False
End With





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Dynamic Web Queries

I have EXACTLY the same probleml. I have been using VBA to get quotes from
Yahoo for over a year. Never a problem. Recently (last week or two) I have
started getting the Application defined or Object defined error on the
..refresh statement. It happens intermittently: five queries, each one or
two seconds apart, might work fine then suddenly (with the same stock codes)
I'll get this error. NO CODE HAS CHANGED for over a year. It's NOT that
the VBA code doesn't work -- it has been working fine for over a year. Now
(on all four of my PCs) I'm getting this problem. I cannot work around it as
it's completely random.

It's as if Yahoo is sending back some sort of invalid response -- I can't
think what else it could be.

It happens under 2000 and 2003. (I haven't tried other versions).

Something (not my code) has changed recently to cause this intermittent
problem.



"Matt Day" wrote in message
...
Thank you for looking at my problem. I understand what you are saying, but

I
require the ability to change the query through the code, therefore I

often
times need to be able to add a new query. But when I do this, I have no

need
for the old query although the old queries seem to remain in the
spreadsheet.

Now, I have modified my code so that it no longer requires 5 queries,

rather
just 1. But, even with your suggestion below and simplifying the code, I

am
often times getting an Application defined error when the code attempts to
refresh the query. It does not happen every time. I just dont understand

why
the refresh is not working all the time as I have used the refresh command
in other spreadsheets. Could it have to do with multiple queries existing
for the same cell due to the QuerTables.Add function or something along
those lines? Or could the web query be timing out and not getting all of

the
data?

Basically the code seems to be running great except for this Application
defined or Object defined error with respect to refreshing the query. Any
further assistance that anyone can provide would be wonderful.

Thanks again for all the help Tushar!

Matt Day

"Tushar Mehta" wrote in message
news:MPG.1a7c288da59dea7b98968e@news-server...
If you analyze your code, you will realize that each time it is
executed you are adding a new query ...QueryTables.Add(...

Instead, turn on the macro recorder (Tools | Macro Record new
macro...), refresh an existing query, and turn off the recorder. XL
will give you the necessary code to reuse an existing query. It should
be something like:

Range("B2").Select
Selection.QueryTable.Refresh BackgroundQuery:=False

which can be modified to

Range("B2").QueryTable.Refresh BackgroundQuery:=False


--
Regards,

Tushar Mehta, MS MVP -- Excel
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article , fourstar77
@hotmail.com says...
Hello,

I am attempting to use the below code to run some web queries via my

macro.
I am often times getting an Application defined or Object defined

error
on
the .Refresh BackgroundQuery part. I have about 5 of these queries in

my
macro and the error can happen in any of them and there does not

appear
to
be a pattern. I dont know if the program is having problems connecting

to
the online information or what might be causing this, but I have had
multiple web queries run through a macro and have never received this

error.
I tried tossing some Application.wait code in there but that did not

seem to
help. Does anyone have any suggestions on this?

Also, as I run this macro over and over (I need to run it each day to

gather
data) "ExternalData_x" items are being created with respect to these

web
queries. To explain this further you can see this under the Insert -

Name -
Define menu. I can delete these manually but would prefer that they

arent
saved at all in the spreadsheet if this is at all detrimental. I have

the
macro deleting the QueryTables with Selection.QueryTable.Delete, but

these
ExternalData_x. Any suggestions on this?

Thanks

Matt

With Sheets("RawData").QueryTables.Add(Connection:="URL ;" & url, _
Destination:=Sheets("RawData").Range("b2"))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = False
End With







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic pivot table linked to dynamic excel spreadsheets FErd Excel Worksheet Functions 0 April 29th 10 10:44 PM
Dynamic chart pasted to a new workbook in report can't be dynamic Piotr (Peter)[_2_] Charts and Charting in Excel 2 August 6th 08 05:15 AM
Help with copying dynamic column selected based on remote cell value and dynamic formula fill ers Charts and Charting in Excel 0 March 1st 06 01:05 AM
Dynamic Range with unused formula messing up x axis on dynamic graph [email protected] Charts and Charting in Excel 2 February 2nd 06 08:02 PM
Dynamic Web Queries Chuck Taylor Excel Programming 1 January 27th 04 04:27 AM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"