PDA

View Full Version : Refresh HTML file BEFORE importing to workbook



xluser2007
12-08-2008, 07:40 PM
Hi All,

I have few html files which contain tables I need to import.

I have written the following code, which works, but I would like to ensure that the HTML tables are REFRESHED before the table is copied from them.

How would I go about doing this?

Option Explicit

Sub Import_HTML_Table(strSourceHTMLfile As String, rngDestRange As Range, strDestNmdrng As String)

With rngDestRange.Parent.QueryTables.Add(Connection:= _
"FINDER;file:" & strSourceHTMLfile _
, Destination:=rngDestRange)


.Name = strDestNmdrng

.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.SaveData = True
.RefreshStyle = xlOverwriteCells ' This is important
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "2"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False

End With

End Sub

Sub test()

Call _
Import_HTML_Table(ThisWorkbook.Worksheets("Parameters").Range("HTMLOutputPath").Value _
& "\bucket_0K.html", _
ThisWorkbook.Worksheets("Common_Law_Intimations").Range("RIC_bucket_0K"), "bucket0K")

End Sub
Any help appreciated.

xluser2007
12-09-2008, 11:58 AM
Any suggestions for this query VBAXers? I assume its one of the options in the querytable that should be set to true, but am not sure which one it is.

The other option is to manually open up the HTML, and use SendKeys to hit F5 i.e. html refresh, close the HTML down and then use the displayed macro.

Though I am sure that the first option is probably easier to do.

Any suggestions appreciated.