vba-在TXT文档末尾中加入文字
Sub 在TXT文档末尾加入文字()
Dim myPath$, myFile$, AK As Workbook
Application.DisplayAlerts = False '禁用警告提示
Application.ScreenUpdating = False '冻结屏幕,以防屏幕抖动
myPath = "G:\新建文件夹\" '在这里输入你的路径,即你存放工作簿的文件夹
myFile = Dir(myPath & "*.txt") '依次找寻指定路径中的*.xlsx文件
Do While myFile <> "" '当指定路径中有文件时进行循环
a = myPath & myFile
Open a For Append As #1 's输入地址后打开,本文本文档的名字是#1
If EOF(1) = True Then
Print #1, Cells(1, 1) '写入
Print #1, Cells(2, 1)
Print #1, Cells(3, 1)
End If
Close #1
myFile = Dir '找寻下一个*.xlsx文件
Loop
Application.ScreenUpdating = True '解除冻结屏幕,此类语句一般成对使用
Application.DisplayAlerts = True '恢复警告提示
End Sub
