Hi All,
I am trying to import data from a web page with a standard web address with an incremental number that identifies the web page required (weather data from a web page).
However, the macro I have at the moment is not copying in the web page. I think that the issue is that the web address is not being copied from the designated cell and the clipboard is being wiped. Does anybody know how to work around that, or how to insert a loop to state the required web page?
If you would like to see the web address:
<TBODY>
</TBODY><COLGROUP><COL></COLGROUP>
The section in colour is what changes per page, increasing by 1800 each time.
Thanks for your time.
D
I am trying to import data from a web page with a standard web address with an incremental number that identifies the web page required (weather data from a web page).
However, the macro I have at the moment is not copying in the web page. I think that the issue is that the web address is not being copied from the designated cell and the clipboard is being wiped. Does anybody know how to work around that, or how to insert a loop to state the required web page?
Code:
Sub ImportData()
'
' ImportData Macro
' Retrieves the next set of data from the website.
'The Usual
Application.ScreenUpdating = False
Application.DisplayAlerts = False
LineNumber = Sheets("Summary").Range("G2")
For i = LineNumber To 10
Sheets("Summary").Range("G2") = LineNumber
Sheets("Summary").Calculate ' these 2 lines make sure a new URL is generated on the summary tab
URLToGet = Sheets("Summary").Range("G7")
'The Macro
Sheets("Summary").Select
Range("G7").Select
Selection.Copy
Sheets("Import").Select
Application.CutCopyMode = True
With ActiveSheet.QueryTables.Add(Connection:= _
"URL; " & URLToGet _
, Destination:=Range("$A$1"))
.Name = _
"current?LANG=en&DATE=1199059200&CONT=ukuk&LAND=UK&KEY=UK&SORT=1&UD=0&INT=06&TYP=temperatur&ART=tabelle&RUBRIK=akt&R=310&CEL=C&SI=mph_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
End With
Sheets("weather test").Select
Range("C2").Select
Selection.Copy
Sheets("Summary").Select
Dim FirstBlankCell As Range
Set FirstBlankCell = Range("D" & Rows.Count).End(xlUp).Offset(1, 0)
FirstBlankCell.Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Import").Select
Cells.Select
Selection.ClearContents
Next i
'The usual
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
If you would like to see the web address:
http://www.weatheronline.co.uk/weather/maps/current?LANG=en&DATE=1072915200&CONT=ukuk&LAND=UK&KEY=UK&SORT=1&UD=0&INT=06&TYP=temperatur&ART=tabelle&RUBRIK=akt&R=310&CEL=C&SI=mph</SPAN> |
<TBODY>
</TBODY><COLGROUP><COL></COLGROUP>
The section in colour is what changes per page, increasing by 1800 each time.
Thanks for your time.
D