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 < 35 Then
m = Left(n, Len - 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.
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 < 35 Then
m = Left(n, Len - 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.