Import htm to excel

fajridotnet

New Member
Joined
Dec 18, 2012
Messages
1
Hi all excel expert,

I'm a new member in this forum, I need some help from all of you. I want to import htm file into excel worksheet. I tried macro below, it give success operation for importing but it is not recognizing correct column so the result
======code===source:http://www.mrexcel.com/forum/excel-questions/389280-htm-excel-different-sheets.html=====

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 = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False
End With
End If
Next e
MsgBox "collating is complete."
End Sub
===================Original report in htm file====================
01-Jan-12 07:40:01 RPT011: GPF1 : Periodic : Page 1

Category: All Activity
Event location: On-Line
Area: Source: 1*
Description:
Operator: Period: 31-Dec-11 07:40:01 to 01-Jan-12 07:40:01

Event file 1: 22-Sep-08 18:20:48 to 01-Jan-12 07:40:00

Time Source Condition Level Description Value Units Operat
---------------------------------------------------------------------------------------------------------
12/31/2011 7:40:48.527 132LT131 Loop Cu~ L 00 ON
12/31/2011 7:40:49.527 132LT131 Loop Cu~ OK L 00 OFF
12/31/2011 7:40:51.527 132LT129 Loop Cu~ L 00 ON
12/31/2011 7:40:53.527 132LT129 Loop Cu~ OK L 00 OFF
12/31/2011 7:41:50.534 132LT131 Loop Cu~ L 00 ON

==============Result in excel after importing=================
01-Jan-12 07:40:01 RPT011: GPF1 :Periodic : Page 1
01-Jan-12 07:40:01 RPT011:GPF1 :</SPAN></SPAN> Periodic : Page 1</SPAN>
Category: All Activity
Event location: On-Line
Area: Source: 1*
Description:
Operator: Period: 31-Dec-117:40:01to1-Jan-127:40:01
Event file 1: 22-Sep-08 18:20:48to 01-Jan-127:40:00
Time SourceConditionLevelDescriptionValueUnits Operat
-----------------------------------------------------------------------------------------------------------------------------------------------
12/31/2011 7:40:48.527 132LT131Loop Cu~L 00ON
12/31/2011 7:40:49.527 132LT131Loop Cu~OKL 00OFF
12/31/2011 7:40:51.527 132LT129Loop Cu~L 00ON
12/31/2011 7:40:53.527 132LT129Loop Cu~OKL 00OFF
12/31/2011 7:41:50.534 132LT131Loop Cu~L 00ON
12/31/2011 7:41:52.534 132LT131Loop Cu~OKL 00OFF

<COLGROUP><COL style="WIDTH: 176pt; mso-width-source: userset; mso-width-alt: 8557" width=234><COL style="WIDTH: 50pt; mso-width-source: userset; mso-width-alt: 2413" width=66><COL style="WIDTH: 31pt; mso-width-source: userset; mso-width-alt: 1499" width=41><COL style="WIDTH: 56pt; mso-width-source: userset; mso-width-alt: 2742" width=75><COL style="WIDTH: 104pt; mso-width-source: userset; mso-width-alt: 5046" width=138><COL style="WIDTH: 37pt; mso-width-source: userset; mso-width-alt: 1792" width=49><COL style="WIDTH: 21pt; mso-width-source: userset; mso-width-alt: 1024" width=28><COL style="WIDTH: 33pt; mso-width-source: userset; mso-width-alt: 1609" width=44><COL style="WIDTH: 97pt; mso-width-source: userset; mso-width-alt: 4717" width=129><COL style="WIDTH: 51pt; mso-width-source: userset; mso-width-alt: 2486" width=68><COL style="WIDTH: 97pt; mso-width-source: userset; mso-width-alt: 4717" width=129><TBODY>
</TBODY>

====question===
how to modified the code above to separate Time, Source, Condition, Level, Description, Value, Unite, Operation in correct column. If you want to try with original file, I'll let you received the file through email.

thanks
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,216,101
Messages
6,128,838
Members
449,471
Latest member
lachbee

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