知道为什么这段代码产生运行时1004错误?
Dim outputHtml As String, tbody As String
outputHtml = Right(htmlCode, Len(htmlCode) - InStr(htmlCode, "<div class=""b-campaign-stat-data b-campaign-stat-data_type_custom"">") + 1)
tbodyStart = InStr(outputHtml, "<tbody")
tbodyEnd = InStr(outputHtml, "</tbody>")
tbody = Mid(outputHtml, tbodyStart, tbodyEnd + 8 - tbodyStart)
outputHtml = WorksheetFunction.Substitute(outputHtml, tbody, "g")
这是绊倒它的最后一行。我也试过Application.Substitute
......
答案 0 :(得分:1)
您尚未声明tbodyEnd
变量。将其添加到您的代码中:
Dim tbodyEnd As String
注意,您可以启用“Option Explicit”以避免将来出现此类问题。有两种方法可以做到这一点:
Option Explicit
添加到模块顶部,或当您未声明变量时,执行其中任何一项都会导致更有意义的警告/错误。它将为您提供变量的名称,这很有帮助。