VBA Code to copy Chrome html doc to excel

Sivas

New Member
Joined
Aug 29, 2018
Messages
20
Can anyone explain, how to copy .htm data to excel. I have the code as below, but it's copying all unwanted data also.

Sub Pull_html()
Dim z As Long, e As Long
Dim f As String, m As String, n As String
Sheets("Sheet1").Select
Cells(1, 1) = "=cell(""filename"")"
Cells(1, 2) = "=left(A1,find(""["",A1)-1)"
Cells(2, 1).Select
f = Dir(Cells(1, 2) & "*.htm")
Do While Len(f) > 0
ActiveCell.Formula = f
ActiveCell.Offset(1, 0).Select
f = Dir()
Loop
z = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For e = 2 To z
n = Sheets("Sheet1").Cells(e, 1)
If n <> ActiveWorkbook.Name Then
If Len(n) < 35 Then
m = Left(n, Len(n) - 4)
Else
m = Left(n, 31)
End If
Sheets.Add.Name = m
With ActiveSheet.QueryTables.Add(Connection:="URL;file:///" & Sheets("Sheet1").Cells(1, 2) & Sheets("Sheet1").Cells(e, 1), _
Destination:=Sheets(m).Range("A1"))
.Name = "goodbites"
.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 = False
.WebConsecutiveDelimitersAsOne = False
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False
End With
End If
Next e
MsgBox "collating is complete."
End Sub

In .htm doc the fields looks like

[TABLE="class: report"]
<tbody>[TR]
[TH="class: tl, colspan: 1"]Document And Entity Information (USD $)

[/TH]
[TH="class: th, colspan: 1"]6 Months Ended[/TH]
[TH="class: th, colspan: 1"][/TH]
[TH="class: th, colspan: 1"][/TH]
[/TR]
[TR]
[TH="class: th"]Jun. 30, 2018[/TH]
[TH="class: th"]Jul. 31, 2018[/TH]
[TH="class: th"]Dec. 31, 2017[/TH]
[/TR]
[TR="class: re"]
[TD="class: pl"]Document Information [Line Items][/TD]
[TD="class: text"] [/TD]
[TD="class: text"] [/TD]
[TD="class: text"] [/TD]
[/TR]
[TR="class: ro"]
[TD="class: pl"]Document Type[/TD]
[TD="class: text"]10-Q[/TD]
[TD="class: text"] [/TD]
[TD="class: text"] [/TD]
[/TR]
[TR="class: re"]
[TD="class: pl"]Amendment Flag[/TD]
[TD="class: text"]false[/TD]
[TD="class: text"] [/TD]
[TD="class: text"] [/TD]
[/TR]
[TR="class: ro"]
[TD="class: pl"]Document Period End Date[/TD]
[TD="class: text"]Jun. 30, 2018[/TD]
[TD="class: text"] [/TD]
[TD="class: text"] [/TD]
[/TR]
[TR="class: re"]
[TD="class: pl"]Document Fiscal Year Focus[/TD]
[TD="class: text"]2018[/TD]
[TD="class: text"] [/TD]
[TD="class: text"] [/TD]
[/TR]
[TR="class: ro"]
[TD="class: pl"]Document Fiscal Period Focus[/TD]
[TD="class: text"]Q2[/TD]
[TD="class: text"] [/TD]
[TD="class: text"] [/TD]
[/TR]
[TR="class: re"]
[TD="class: pl"]Entity Registrant Name[/TD]
[TD="class: text"]Macquarie Infrastructure Corp[/TD]
[TD="class: text"] [/TD]
[TD="class: text"] [/TD]
[/TR]
[TR="class: ro"]
[TD="class: pl"]Entity Central Index Key[/TD]
[TD="class: text"]0001289790[/TD]
[TD="class: text"] [/TD]
[TD="class: text"] [/TD]
[/TR]
[TR="class: re"]
[TD="class: pl"]Current Fiscal Year End Date[/TD]
[TD="class: text"]--12-31[/TD]
[TD="class: text"] [/TD]
[TD="class: text"] [/TD]
[/TR]
[TR="class: ro"]
[TD="class: pl"]Entity Filer Category[/TD]
[TD="class: text"]Large Accelerated Filer[/TD]
[TD="class: text"] [/TD]
[TD="class: text"] [/TD]
[/TR]
[TR="class: re"]
[TD="class: pl"]Trading Symbol[/TD]
[TD="class: text"]MIC[/TD]
[TD="class: text"] [/TD]
[TD="class: text"] [/TD]
[/TR]
[TR="class: ro"]
[TD="class: pl"]Entity Common Stock, Shares Outstanding[/TD]
[TD="class: text"] [/TD]
[TD="class: nump"]85,370,832[/TD]
[TD="class: text"] [/TD]
[/TR]
[TR="class: re"]
[TD="class: pl"]Common Stock, Par or Stated Value Per Share[/TD]
[TD="class: nump"]$ 0.001[/TD]
[TD="class: nump"]$ 0.001[/TD]
[TD="class: nump"]$ 0.001
[/TD]
[/TR]
</tbody>[/TABLE]


I need only the data which is visible in doc. But its copying all extra unwanted data in excel. Could anyone help on this.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Forum statistics

Threads
1,225,635
Messages
6,186,128
Members
453,340
Latest member
Stu61

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