将StringBuilder类写入HTML错误:对象必需

感谢Stack Overflow上的精彩团队,下面是创build的代码。 它奇妙的工作,除了最后的错误,我不能揭穿。

类:

Private m_arrBuffer Private m_strDelimiter Private Sub Class_Initialize() m_arrBuffer = Array() m_strDelimiter = “” End Sub Private Sub Class_Terminate() m_arrBuffer = Empty End Sub Public Property Get Delimiter() Delimiter = m_strDelimiter End Property Public Property Let Delimiter(strDelimiter) m_strDelimiter = strDelimiter End Property Public Sub Append(strValue) ReDim Preserve m_arrBuffer(UBound(m_arrBuffer) + 1) m_arrBuffer(UBound(m_arrBuffer)) = strValue End Sub Public Sub AppendLine(strValue) Me.Append strValue & vbCrLf End Sub Public Sub Compact() If Not Me.Delimiter = “” Then strOriginalDelimiter = Me.Delimiter Me.Delimiter = “” End If strTemp = Me.ToString m_arrBuffer = Array() Me.Append strTemp Me.Delimiter = strOriginalDelimiter End Sub Public Function ToArray() ToArray = m_arrBuffer End Function Public Function ToString() ToString = Join(m_arrBuffer, m_strDelimiter) End Function 

代码(信贷到@Bond)

 Dim sb Set sb = New StringBuilder ' Guessing here. You haven't shown the class name. sb.Append "some string" sb.Append "another string" sb.Append "a third string" .... sb.Delimiter = "<br>" myHtmlFile.Write sb.ToString() 

我在myHtmlFile.Write sb.ToString()运行时错误“424”收到错误:需要的对象。

我不确定,但我相信这是我有一个工作代码之前的最后一个障碍。 任何关于如何缓解这个错误的build议? 谢谢。

对于你的问题,我会说解决scheme是:这段代码已经假设,string已完成

 Sub CreateAfile Dim ie As Object, fs as object Dim sb Set sb = New StringBuilder ' Guessing here. You haven't shown the class name. sb.Append "some string" sb.Append "another string" sb.Append "a third string" .... sb.Delimiter = "<br>" Set fs = CreateObject("Scripting.FileSystemObject") Set myHtmlFile = fs.CreateTextFile("U:\temp\MyHTMLfile.htm", True) myHtmlFile.WriteLine(sb.ToString()) myHtmlFile.Close Set ie = CreateObject("Internetexplorer.Application") ie.Visible = True ie.Navigate "U:\temp\MyHTMLfile.htm" End Sub