[英]How to Copy and Paste Into Text File and Save Based on Column Row Data
下面是一些 VBA 循环遍历工作表上的所有行,在以 A 列中的数据命名的指定文件夹中创建一个文本文件,并将 R 列中的数据写入它。
Sub sSaveData(strFolder As String)
On Error GoTo E_Handle
Dim strFile As String
Dim intFile As Integer
Dim lngLastRow As Long
Dim lngLoop1 As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
If Right(strFolder, 1) <> "\" Then strFolder = strFolder & "\"
lngLastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
For lngLoop1 = 1 To lngLastRow
strFile = strFolder & ws.Cells(lngLoop1, 1) & ".txt"
intFile = FreeFile
Open strFile For Output As intFile
Print #intFile, ws.Cells(lngLoop1, 18)
Close #intFile
Next lngLoop1
sExit:
On Error Resume Next
Set ws = Nothing
Reset
Exit Sub
E_Handle:
MsgBox Err.Description & vbCrLf & "sSaveData", vbOKOnly + vbCritical, "Error: " & Err.Number
Resume sExit
End Sub
问候,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.