[英]Copy Entire HTML File Text to a Cell in Excel using VBA
I have an HTML file that I wrote to create a string. 我有一个编写用于创建字符串的HTML文件。 The file is called MyHTMLfile
and it is located in U:\\temp
. 该文件称为MyHTMLfile
,位于U:\\temp
。
How can I easily (and with as little as possible computing time) copy the entire string from HTML to Range("IV" & RowCount)
? 如何轻松地(并以尽可能少的计算时间)将整个字符串从HTML复制到Range("IV" & RowCount)
?
If you want the entire file to be put in a single cell... 如果要将整个文件放在一个单元格中...
With CreateObject("Scripting.FileSystemObject")
Range("IV" & RowCount) = .OpenTextFile("u:\temp\myhtmlfile.htm").ReadAll()
End With
This is assuming your myHtmlFile
has an extension of .htm
. 这是假设您的myHtmlFile
的扩展名为.htm
。 Change as needed. 根据需要进行更改。
How's something like this: 怎么样呢?
Sub test21()
'Thanks to http://stackoverflow.com/questions/11528694/read-parse-text-file-line-by-line-in-vba
Dim FileNum As Integer, i As Integer
Dim DataLine As String
FileNum = FreeFile()
Open "U:\Temp\myHTMLFile.html" For Input As #FileNum
i = 1 ' This is where you want to set your `RowCount`.
While Not EOF(FileNum)
Line Input #FileNum, DataLine ' read in data 1 line at a time
Range("IV" & i).Value = DataLine
i = i + 1
Wend
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.