Hi I wrote this code. but this code is very slow. How can I optimize this code?
Private Sub printItem(r, lastCol, objStream)
FirstCol = 1
Dim strFirst As String
strFirst = CStr(ActiveSheet.Cells(r, 1).Value)
If strFirst = "" Then
Exit Sub
End If
objStream.WriteText " <"
objStream.WriteText "TagName"
objStream.WriteText " "
For c = FirstCol To lastCol
data = CStr(ActiveSheet.Cells(r, c).Value)
If LenB(Trim$(data)) > 0 Then
objStream.WriteText g_AttributeName(c)
objStream.WriteText "="""
objStream.WriteText data
objStream.WriteText """ "
End If
Next c
objStream.WriteText "/>"
objStream.WriteText vbNewLine
End Sub
WriteTextcalls are going to cost you, though that depends on whatobjStreamis writing to. A file will be faster than a console. Bottom line - I'm not sure you can do much better.