vba-在TXT文檔末尾中加入文字
Sub 在TXT文檔末尾加入文字()
Dim myPath$, myFile$, AK As Workbook
Application.DisplayAlerts = False '禁用警告提示
Application.ScreenUpdating = False '凍結(jié)屏幕,以防屏幕抖動(dòng)
myPath = "G:\新建文件夾\" '在這里輸入你的路徑,即你存放工作簿的文件夾
myFile = Dir(myPath & "*.txt") '依次找尋指定路徑中的*.xlsx文件
Do While myFile <> "" '當(dāng)指定路徑中有文件時(shí)進(jìn)行循環(huán)
? ? a = myPath & myFile
? ? Open a For Append As #1 's輸入地址后打開(kāi),本文本文檔的名字是#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 '找尋下一個(gè)*.xlsx文件
Loop
Application.ScreenUpdating = True '解除凍結(jié)屏幕,此類語(yǔ)句一般成對(duì)使用
Application.DisplayAlerts = True '恢復(fù)警告提示
End Sub

標(biāo)簽:vba