我有一个来自HTML源代码(大约1,000,000个字符长)的大字符串。我使用msinet.ocx查看适当网站的文本。为了找到恰好在不同关键短语(“Component Accessory Matrix”)之前出现的关键短语(“pkid =”),我写了一小段代码,但它不能正常工作。这是我现在有的:使用VBA对字符串长度有限制吗?
workbench = Cells(columnNumber, 1).Value
myURL = "http://beams.us.yazaki.com/Beams/ViewDetails.aspx?topic=document&pkid=" _
& workbench
Dim inet1 As Inet
Dim mypage As String
Set inet1 = New Inet
With inet1
.Protocol = icHTTP
.URL = myURL
mypage = .OpenURL(.URL, icString)
End With
CAMnum = InStr(mypage, "Component Accessory Matrix")
intStart = InStrRev(mypage, "pkid=", CAMnum) + 5
newnum = Mid(mypage, intStart, 6)
Cells(columnNumber, 2).Value = newnum
这个问题似乎与mypage = .OpenURL(.URL, icString)
;当我运行len(mypage)
时,它返回约100,000的值,当它应该返回大约一百万的值时。有人可以解释这个吗?
编辑:瘸子,我试过你的解决方案,由于某种原因,ReturnStr仍然是空的。我尝试了1024而不是2048,但这并没有改变任何东西。我已经复制并粘贴了我的代码。
Dim myURL
ActiveSheet.Range( “A1”)。完(xlDown)。选择 lastColumn = Selection.Row
对于得到columnnumber = 2至lastColumn 工作台=细胞(得到columnnumber,1)。价值 myURL = “http://beams.us.yazaki.com/Beams/ViewDetails.aspx?topic=document & PKID =” _ &工作台 昏暗inet1作为的Inet 昏暗我的空间作为字符串 昏暗ReturnStr作为字符串
Set inet1 = New Inet
With inet1
.Protocol = icHTTP
.URL = myURL
mypage = .OpenURL(.URL, icString)
ReturnStr = .GetChunk(1024, icString)
End With
Do While Len(ReturnStr) <> 0
DoEvents
mypage = mypage & ReturnStr
ReturnStr = inet1.GetChunk(1024, icString)
Loop
CAMnum = InStr(mypage, "Component Accessory Matrix")
intStart = InStrRev(mypage, "pkid=", CAMnum) + 5
newnum = Mid(mypage, intStart, 6)
Cells(columnNumber, 2).Value = newnum
Next columnNumber
我在这里错过了什么吗?我在网上搜索GetChunk函数,我不认为我在语法上做了任何错误,但也许这是一些基本的错误。帮助表示赞赏。
@MarkHall .OpenURL确实有限制,而不是字符串。 参考:http://www.vbforums.com/showthread.php?t=54096 发表回答下面。 – danielpiestrak 2012-07-11 19:35:41
这是否意味着你不需要帮助[here](http://stackoverflow.com/q/11416301/190829)? – JimmyPena 2012-07-11 20:37:28
@JimmyPena,我很好。 – sresht 2012-07-13 14:02:40