+ Reply to Thread
Results 1 to 2 of 2

macro web query

Hybrid View

DodgeyNY macro web query 08-07-2008, 02:02 PM
Leith Ross Hello DodgeyNY, This will... 08-07-2008, 02:23 PM
  1. #1
    Registered User
    Join Date
    08-07-2008
    Location
    New York
    Posts
    1

    macro web query

    Hi guys,

    I was wondering if you could help me out I want to import data into excel from a large number of tables which are on seperate webpages. The pages run in sequence up to 10000 (see below). What code do I need to add to the macro to add 1 to the id=00001 each time. Cheers.

    http://www.example.com/quote_id=00001
    http://www.example.com/quote_id=00002
    http://www.example.com/quote_id=00003

    and carry on up to id=10000?


    Sub URL_Static_Query()
       
       With ActiveSheet.QueryTables.Add(Connection:= _
          "URL;http://www.example.com/quote_id=00001", _
             Destination:=Range("a1"))
       
          .BackgroundQuery = True
          .TablesOnlyFromHTML = True
          .Refresh BackgroundQuery:=False
          .SaveData = True
       End With
    End Sub

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello DodgeyNY,

    This will format the number with the correct number of leading zeroes.
    Sub URL_Static_Query()
       
      Dim Id As String
      Dim N As Integer
    
       N = 1
       Id = Format(Str(N), "0000#")
    
       With ActiveSheet.QueryTables.Add(Connection:= _
          "URL;http://www.example.com/quote_id=" & Id, _
             Destination:=Range("a1"))
       
          .BackgroundQuery = True
          .TablesOnlyFromHTML = True
          .Refresh BackgroundQuery:=False
          .SaveData = True
       End With
    
    End Sub
    Sincerely,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1