Harlan,
Nice response (as usual). If you pull that IIf out of the loop and instead
lop off the extra SEP at the end, you speed things up, for the OP's case, by
about 12% on the Wintel I am running at the moment; coercing the range to a
variant, one row at a time, plus the above idea, gives code that is about 4
times faster, as follows.
Regards,
Dave Braden
Revised foo:
=========
Option Explicit
Declare Function QueryPerformanceCounter Lib "Kernel32" _
(X As Currency) As Boolean
Declare Function QueryPerformanceFrequency Lib "Kernel32" _
(X As Currency) As Boolean
#Const bPrintTime = True
Sub foo3()
'Original post by Harlan Grove 2003/08/22
'Modified by Dave Braden 2003/08/23
'modify by making these constants variables and using InputBox to change
them
Const SEP As String = ","
Const FN As String = "C:\output.csv"
Dim l As Long, k As Long, lLastRow As Long, lFd As Long
Dim s As String, v As Variant
Dim sht As Worksheet, shtColl As Object
#If bPrintTime Then
Dim Count1 As Currency, Count2 As Currency, Freq As Currency
QueryPerformanceFrequency Freq
#End If
On Error GoTo HandleErr
lFd = FreeFile
Open FN For Output As #lFd
'determine sheets to print side-by-side
Set shtColl = ActiveWorkbook.Worksheets
'establish greatest rownumber of all sheets
For Each sht In shtColl
With sht.UsedRange: l = .Row + .Rows.Count - 1: End With
If l > lLastRow Then lLastRow = l
Next
#If bPrintTime Then
QueryPerformanceCounter Count1
#End If
For l = 1 To lLastRow
s = ""
For Each sht In shtColl
v = sht.Rows(l)
For k = 1 To 256
s = s & SEP & v(1, k)
Next
Next
Print #lFd, Mid(s, 1 + Len(SEP))
Next
#If bPrintTime Then
QueryPerformanceCounter Count2
Debug.Print (Count2 - Count1) / Freq ' * 1000 & " mSec"
#End If
HandleErr:
Close #lFd
End Sub
=============