我正在使用此代码将台式机中的txt文件导出,效果很好,但是每次使用此代码时,我都需要将所选单元格导出到txt文件的末尾:>
Sub ExportToTxtFile()
Dim myFile As String, txtname As Range, rng As Range, cellValue As Variant, i As Integer, j As Integer
Set txtname = Range("H1")
myFile = Environ("USERPROFILE") & "\Desktop\" & txtname & ".txt"
Set rng = Selection
Open myFile For Output As #1
For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
cellValue = rng.Cells(i, j).Value
If j = rng.Columns.Count Then
Print #1, cellValue
Else
Print #1, cellValue,
End If
Next j
Next i
Close #1
End Sub