Update of web queries (macro)

NelsonX

New Member
Joined
Feb 23, 2008
Messages
29
Hi all,

I have a macro which runs various web queries (as opposed to updating individually using the toolbar); and is also based on cell input. In addition to this I want to automate other procedures like copying formats to retain a specific format to my web queries. For example, here is an extract of the code:

----
Sub Test()
Sheet10.QueryTables.Item("ReutersCashFlowStatementI").Connection = _
"URL;http://www.reuters.com/finance/stocks/incomeStatement?stmtType=CAS&perType=INT&symbol=" _
& Sheet10.Cells(5, 3) & Sheet1.Cells(34, 3)
Sheet10.QueryTables.Item("ReutersCashFlowStatementI").Refresh

'Copy Formats After Data Download
Sheets("HiddenSheet(2)").Range("B5:R295").Copy
Sheets("Financial Statements (Reuters)").Range("B9").Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Range("C5").Select
----

The problem is that the 'copy' part of the code doesn't work. It appears that this part runs before the data is downloaded from the web. Is there anyway to pause or delay the code so that this works? I hope I've explained this properly.

Nelson
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
7,791
Try changing:

Sheet10.QueryTables.Item("ReutersCashFlowStatementI").Refresh

To:

Sheet10.QueryTables.Item("ReutersCashFlowStatementI").Refresh BackgroundQuery:=False

You want the Refresh to be synchronous so that it waits for the data to be retrieved before continuing with the copy part.
 
Upvote 0

Forum statistics

Threads
1,191,189
Messages
5,985,197
Members
439,947
Latest member
fabiannic

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top