孤独的猫

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 将文件夹下的所有txt文件加载到本文档中

Function InsertIntoDoc(strPath as String)

Set fso=CreateObject("Scripting.FileSystemObject”)

Set objFolder=fso.GetFolder(strPath)

Set objFiles =objFolder.Files

Str1=””

For Each objFile In objFiles

Debug.Print objFile.Name

Set fout=fso.OpenTextFile(strPath & “\” & objFile.Name,1,False)

tmpOut=fout.ReadAll

str1=str1 & objFile.Name & chr(13)

str1=str1 & tmpOut & chr(13) & chr(13) & chr(13)

Next

Selection.TypeText Text:=str1

End Function

Sub CommandButton1_Click()

Call InsertIntoDoc(路径)

End Sub

Function InsertIntoDoc(strPath as String)

Set fso=CreateObject("Scripting.FileSystemObject”)

Set objFolder=fso.GetFolder(strPath)

Set objFiles =objFolder.Files

Str1=””

For Each objFile In objFiles

Debug.Print objFile.Name

Set fout=fso.OpenTextFile(strPath & “\” & objFile.Name,1,False)

tmpOut=fout.ReadAll

str1=str1 & objFile.Name & chr(13)

str1=str1 & tmpOut & chr(13) & chr(13) & chr(13)

Next

Selection.TypeText Text:=str1

End Function

Sub CommandButton1_Click()

Call InsertIntoDoc(路径)

End Sub

posted on 2011-07-22 20:50  孤独的猫  阅读(397)  评论(0编辑  收藏  举报