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 < 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 = 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=================
<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
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 < 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 = 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 : | Peri | odic : Page 1 | ||||||||
01-Jan-12 07:40:01 RPT011:GPF1 :</SPAN></SPAN> | Peri | odic : Page 1</SPAN> | ||||||||
Category: All Activity | ||||||||||
Event location: On-Line | ||||||||||
Area: Source: 1* | ||||||||||
Description: | ||||||||||
Operator: Period: 31-Dec-11 | 7:40:01 | to | 1-Jan-12 | 7:40:01 | ||||||
Event file 1: 22-Sep-08 18:20:48 | to 01-J | an-12 | 7:40:00 | |||||||
Time Source | Conditio | n | 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 | |||||||
12/31/2011 7:41:52.534 132LT131 | Loop Cu~ | OK | L 00 | OFF |
<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