Trying to import a html file into a single cell.

mikeybabes

New Member
Joined
Dec 8, 2015
Messages
4
I have some relatively small HTML files, pretty much plain text in UTF-8 format. But no matter what I'm unable to get to load into a string.
I've scanned everywhere Microsoft own help documents are pretty US.

I could use copy/paste, but there is no fun in this, and also I have 200+ files which I will import from.


Code:
Sub InsertHTML()
Dim htFilename As Variant
Dim r As Long
Dim Filename As String
Dim Filenum As Integer
Dim strString As String
Dim iPtr As Long


iRow = 1
ICol = xColIndex = Application.ActiveCell.Column


htFilename = Application.GetOpenFilename(FileFilter:="HTML files (*.html), *.html", MultiSelect:=True)
If Not IsArray(htFilename) Then Exit Sub


For iPtr = LBound(htFilename) To UBound(htFilename)
 Filename = htFilename(iPtr)
    Open Filename For Input As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] 
       Get [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] , , strString
            Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=1]#1[/URL] 
                Cells(iRow, ICol).Value = strString
    iRow = iRow + 1
Next iPtr
End Sub

The failure is the Open Filename.

Anyone have an idea on this simple project, your help is appreciated.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Welcome to the forum.

Something like this should work:

Rich (BB code):
Sub InsertHTML()
Dim htFilename As Variant
Dim r As Long
Dim Filename As String
Dim Filenum As Integer
Dim strString As String
Dim iPtr As Long
Dim iRow As Long
Dim iCol As Long


iRow = 1
iCol = Application.ActiveCell.Column


htFilename = Application.GetOpenFilename(FileFilter:="HTML files (*.html), *.html", MultiSelect:=True)
If Not IsArray(htFilename) Then Exit Sub


For iPtr = LBound(htFilename) To UBound(htFilename)
 Filename = htFilename(iPtr)
    Open Filename For Input As #1 
       Input #1 , strString
            Close #1 
                Cells(iRow, iCol).Value = strString
    iRow = iRow + 1
Next iPtr
End Sub
 
Upvote 0
Curious. It worked with my sample file, but not with yours. Try this instead:

Rich (BB code):
Sub InsertHTML()
Dim htFilename As Variant
Dim r As Long
Dim Filename As String
Dim Filenum As Integer
Dim strString As String
Dim iPtr As Long
Dim iRow As Long
Dim iCol As Long


iRow = 1
iCol = Application.ActiveCell.Column


htFilename = Application.GetOpenFilename(FileFilter:="HTML files (*.html), *.html", MultiSelect:=True)
If Not IsArray(htFilename) Then Exit Sub


For iPtr = LBound(htFilename) To UBound(htFilename)
 Filename = htFilename(iPtr)
    Open Filename For Input As #1 
    strString = Input(LOF(1), #1 )
            Close #1 
                Cells(iRow, iCol).Value = strString
    iRow = iRow + 1
Next iPtr
End Sub
 
Upvote 0
Beautiful.....total perfection.

That's some beer tokens on account for you.

Many thanks for your help, hope you have a great day.

BR
Michael
 
Upvote 0
Beautiful.....total perfection.

That's some beer tokens on account for you.

Many thanks for your help, hope you have a great day.

BR
Michael

Eat my own words, I just notice, the HTML files have some Unicode characters, the files are exported as utf-8.
They open fine with notepad. And even when copy/paste into excel cell.
I'm not sure if need some string conversion done on the import.

BR
Michael.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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