【发布时间】:2013-02-20 21:08:25
【问题描述】:
我正在使用以下代码将行导出到单个文本文件:
Sub export_Test()
Dim firstRow As Integer, lastRow As Integer, fileName As String
Dim myRow As Integer, myStr As String
firstRow = 10
lastRow = 29
For myRow = firstRow To lastRow
fileName = "C:\mallet\test\" & Cells(myRow, 1) & ".txt"
Open fileName For Append As #1
myStr = Cells(myRow, 2).Value
Print #1, myStr
Close #1
Next
End Sub
问题在于此代码用于特定数量的行。我想将此代码用于不同的数据样本,因此 excel 文件中的行数会有所不同,并且可能数以千计。我需要将 lastRow 变量设置为无限数,并在遇到空行时退出 For 循环。
【问题讨论】:
-
另外,由于您使用的是 Rows,建议将它们声明为
Long而不是integers:) -
@Sid 在 32 位操作系统上,您应该始终使用
Long,除非特别需要使用 16 位数字 (Integer)