Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data loading on wrong Excel sheet.

Status
Not open for further replies.

basil3legs

Programmer
Jun 13, 2002
157
GB
I am running a VBA function that repeatedly opens webpages and then extracts data from them. I have a seperate sheet setup for the webpages to load into but every so often they open on another random sheet writing over it's contents. The code I am using to open the pages is:

Code:
        Sheets("Webpages").Select
        Range("A1").Select
        With Selection.QueryTable
            .Connection = "URL;[URL unfurl="true"]http://www.*******.com/page.asp?ssss="[/URL] & Worksheets("AnotherPage").Cells(UrlLine, 1).Value
            .WebSelectionType = xlEntirePage
            .WebFormatting = xlWebFormattingAll
            .WebPreFormattedTextToColumns = True
            .WebConsecutiveDelimitersAsOne = True
            .WebSingleBlockTextImport = False
            .WebDisableDateRecognition = True
            .Refresh BackgroundQuery:=False
        End With

Am I actually doing anything wrong or is Excel just getting it wrong every so often?
 
Instead of:
Sheets("Webpages").Select
Range("A1").Select
With Selection.QueryTable

try:

with Sheets("Webpages").QueryTables(1)


Rgds, Geoff

Three things are certain. Death, taxes and lost data. DPlank is to blame

Please read FAQ222-2244 before you ask a question
 
Cheers Geoff,

I like to see where it is up to so have changed it to use both mentions of "Webpages" which is a bit of overkill but will hopefully also reduce the chance of it messing up.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top