vba读取HTML文档,使用VBA将本地HTML文件读入字符串
发布日期:2021-06-24 16:32:24 浏览次数:2 分类:技术文章

本文共 1736 字,大约阅读时间需要 5 分钟。

osknows..

5

这是一种方法

Option Explicit

Sub test()

Dim oFSO As Object

Dim oFS As Object, sText As String

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set oFS = oFSO.OpenTextFile("C:\Users\osknows\Desktop\import-store.csv")

Do Until oFS.AtEndOfStream

' sText = oFS.ReadLine 'read line by line

sText = oFS.ReadAll()

Debug.Print sText

Loop

End Sub

编辑:

尝试将以下行更改为以下3行之一,看看它是否有任何区别

Set FS = FSO.OpenTextFile("C:\Users\osknows\Desktop\import-store.csv", 1, 0)

Set FS = FSO.OpenTextFile("C:\Users\osknows\Desktop\import-store.csv", 1, 1)

Set FS = FSO.OpenTextFile("C:\Users\osknows\Desktop\import-store.csv", 1, 2)

EDIT2:

这些代码在你那正常吗?

Function ExecuteWebRequest(ByVal url As String) As String

Dim oXHTTP As Object

Set oXHTTP = CreateObject("MSXML2.XMLHTTP")

oXHTTP.Open "GET", url, False

oXHTTP.send

ExecuteWebRequest = oXHTTP.responseText

Set oXHTTP = Nothing

End Function

Function OutputText(ByVal outputstring As String)

MyFile = ThisWorkbook.Path & "\temp.html"

'set and open file for output

fnum = FreeFile()

Open MyFile For Output As fnum

'use Print when you want the string without quotation marks

Print #fnum, outputstring

Close #fnum

End Function

Sub test()

Dim oFSO As Object

Dim oFS As Object, sText As String

Dim Uri As String, HTML As String

Uri = "http://www.forrent.com/results.php?search_type=citystate&page_type_id=city&seed=859049165&main_field=12345&ssradius=-1&min_price=%240&max_price=No+Limit&sbeds=99&sbaths=99&search-submit=Submit"

HTML = ExecuteWebRequest(Uri)

OutputText (HTML)

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set oFS = oFSO.OpenTextFile(ThisWorkbook.Path & "\temp.html")

Do Until oFS.AtEndOfStream

' sText = oFS.ReadLine 'read line by line

sText = oFS.ReadAll()

Debug.Print sText

Loop

End Sub

kZCwf.png

转载地址:https://blog.csdn.net/weixin_33844346/article/details/117784449 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:html如何判断文本框是否为空,javascript怎么判断文本框是否为空?
下一篇:html表格中的滚动字幕,html – 向表格主体添加滚动条

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月01日 23时22分55秒