|
本帖最后由 1234vba 于 2018-9-17 09:17 编辑
手上有一份 隔壁论坛 的赵老师的代码
该代码是插入第一行和第三行,
- Sub Insert()
- On Error Resume Next
- Dim objFSO As Object, objFile As Object, i As Long
- Dim txtpath As String, d As String, allt, s As String
- txtpath = ThisWorkbook.Path & "\test.txt"
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- Set objFile = objFSO.OpenTextFile(txtpath, 1)
- d = objFile.ReadAll
- allt = Split(d, vbCrLf, -1, 1)
- objFile.Close
- Set objFile = objFSO.createtextfile(txtpath, 1)
- s = "插入的内容1" & vbCrLf
- For i = LBound(allt) To 1
- s = s & allt(i) & vbCrLf
- Next
- s = s & "插入的内容2" & vbCrLf
- For i = 2 To UBound(allt)
- s = s & allt(i) & vbCrLf
- Next
- objFile.write s
- objFile.Close
- Set objFile = Nothing: Set objFSO = Nothing
- End Sub
复制代码 我要插入第一行和最后一行数据
UBound(allt)获得文本行数后,
我尝试修改代码。。。。
代码最后只得到4个数据了。包括插入的第一行和第三行。
好奇怪
请各位老师帮忙
谢谢
|
|