' 获取下一个可用的文件句柄编号。
FileNum = FreeFile()
' 关闭错误检查功能。
On Error Resume Next
' 尝试打开目标文件以供输出。
Open DestFile For Output As #FileNum
' 如果出现错误,则报告错误并结束程序。
If Err <> 0 Then
MsgBox "Cannot open filename " & DestFile
End
End If
' 打开错误检查功能。
On Error GoTo 0
' 循环选择的每一行。
For RowCount = 1 To Selection.Rows.Count
' 循环选择的每一列。
For ColumnCount = 1 To Selection.Columns.Count
' 将当前单元格中的文本写入到文件中,文本用引号括起来。
Print #FileNum, """" & Selection.Cells(RowCount, _
ColumnCount).Text & """";
' 检查单元格是否位于最后一列。