I have to edit urgent html text files with macro. I tried to import html file into excel but the text file is broken into parts according cell size. The view is the same but I have to add the cells content to have the original line.
How to solve this job? Any ideas appreciated.
wbr kacor
Microsoft ExcelHTML
Last Comment
dlmille
8/22/2022 - Mon
dlmille
I would read the text file using old fashioned methods.
Here's an example that will read your input into Excel, more "properly".
Option ExplicitSub readHTMLTxtFile()Dim wkb As WorkbookDim wks As WorksheetDim wksOut As WorksheetDim dialogfile As FileDialogDim fName As StringDim wholeLine As StringDim i As Long Set wkb = ThisWorkbook Set wks = wkb.Worksheets("Control Panel") On Error Resume Next Set wksOut = wkb.Worksheets("Output") If Err.Number <> 0 Then Set wksOut = wkb.Worksheets.Add(after:=wkb.Worksheets("Control Panel")) wksOut.Name = "Output" End If On Error GoTo 0 wksOut.Cells.Clear 'clear old output, if exists 'prompt for txt file to read Set dialogfile = Application.FileDialog(msoFileDialogFilePicker) With dialogfile .Filters.Clear .Filters.Add "Text Files (*.txt)", "*.txt", 1 'change extension to .html if that's your extension .AllowMultiSelect = False .InitialView = msoFileDialogViewDetails .InitialFileName = ThisWorkbook.Path & "\" .Title = "Select TEXT File for HTML import" .Show End With If dialogfile.SelectedItems.Count > 0 Then fName = dialogfile.SelectedItems(1) Else fName = "" End If If fName <> "" Then 'read the file in Open fName For Input As #1 Do While Not EOF(1) 'check for end of file Line Input #1, wholeLine 'do something with it wksOut.Range("A1").Offset(i, 0).Value = wholeLine i = i + 1 Loop wksOut.Columns("A").AutoFit Close #1 End IfEnd Sub
Hi Dave,
thanks for the quick answer. Now I'm on the way to return home, and I'll test your suggestion asap.
I've not tested but I see a problem: they can occur some to long lines even up to 1 k or more. Would be this problem?
wbr kacor
dlmille
In Excel 2003, a cell will hold 32767 characters, display 1024, but all is editable in the formula bar.
You asked to have the ability to read it all in without breaking lines. Its now up to you to determine how you want to use the data in Excel.
Here's an example that will read your input into Excel, more "properly".
Open in new window
See attached demonstration workbook.
Cheers,
Dave