web query

Bukol

Board Regular
Joined
Mar 31, 2002
Messages
55
Hi again,
I am trying to retrieve data from an external website using following macro:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 4/21/2002 by Hans
'

'
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://1on1.xxxxxxx.com/admin/girltimes.cgi?girl=Oshin&date=04/20/02", _
Destination:=Range("A1"))
.Name = "02_6"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False
End With
End Sub


I have to extract data for about 1200 girls names (Oshin) each for the last 365 days.
How do I write the code if I want to start with todays date and on the next loop with the same girl but yesterdays date and so on.
For the next girl I would just modify the macro manually.
Hans
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
TsTom,
I've seen you are online, you helped me before. Can you look at this one?
Hans
 
Upvote 0
Hi Bukol.
You want a simple loop back one year by each day of the previous year?
Tom
 
Upvote 0
Tom,
yes, but the date has to be part of the URL line, so I would have to put a placeholder in there and then create a variable with todays date and every loop would start with didacting one day from that variable.
Right?
How?
Hans
 
Upvote 0
Sub QueryPastYear()
Dim FirstDate As Date
Dim CurrentDate As Date

CurrentDate = Now ' or any date that you choose ex. #04/10/2002#
FirstDate = CurrentDate - 365

Do Until CurrentDate = FirstDate
CurrentDate = CurrentDate - 1
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://1on1.xxxxxxx.com/admin/girltimes.cgi?girl=Oshin&date=" & _
Format(CurrentDate, "MM/DD/YY"), _
Destination:=Range("A1"))
.Name = "02_6"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False
End With
Loop
End Sub
 
Upvote 0
Bukol,
I did not test it...
Should work as is...
Just wanted to add.
You should be able to query the database of this site with a range of dates and get one return instead of having to do 365 seperate connections...
What type of database is this?
You may be able to send an SQL statement...
May solve your other problem as well.
Were you ever able to figure out a way to get your list of E-Mails?
Tom
This message was edited by TsTom on 2002-04-21 05:13
 
Upvote 0
Tom,
you are a genius!
Last question: if I only want to retrieve lets say one month, I only have to change:
FirstDate = CurrentDate - 31 (instad of 365)
Correct?
Hans
 
Upvote 0
Correct...
If you will be incuding todays date in the query then make
CurrentDate = yesterdays date
Tom
This message was edited by TsTom on 2002-04-21 09:24
 
Upvote 0
Tom,
1) I have very limited access to that external database. But I am happy with your code now.

2) Yes, I did finally get almost all of my 134000 names which I needed to get their e-mail addresses, but I had to do it the hard way:
Remember I only got 65000+ rows out of 134000 lines of data because of the limitaion in excel.
When I entered "@" as search query, I could be sure I would get all of the customers.
So I searched instead for the 5 vowels a e i o u seperately. That way I got 2450000 names in 5 batches of between 55000 and 30000.
I sorted them aplphabetically and deleted duplicates and I was left with 129000 names. (some guys must have funny names with no vowels in it.)
Hans
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

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
Back
Top