我有大量的Word文件需要合併(連接)到一個文件中,並且使用Word合併(一個接一個)會很耗時。你有沒有經歷過任何可以處理這項工作的工具?合併MS Word文件的工具
4
A
回答
4
Sub MergeAllDocuments(AllDocumentsPath as String, MasterDocumentPath as String)
Dim MasterDocument As Document
Set MasterDocument = Documents.Open(FileName:=MasterDocumentPath)
TheDocumentPath = Dir(AllDocumentsPath , vbNormal)
While TheDocumentPath <> ""
' Append the next doc to the end of the master doc. (The
' special "\EndOfDoc" bookmark is always available!)
MasterDocument.Bookmarks("\EndOfDoc").Range.InsertFile TheDocumentPath
TheDocumentPath = Dir
Wend
MasterDocument.Save
End Sub
MergeAllDocuments "C:\MySeparateDocuments\*.doc", "C:\MasterDocument.doc"
我有一個問題 - 爲什麼你要不要做這樣的事情(與文檔的「數量巨大」,至少)?
0
您是否嘗試過使用Word COM API?你可以自動化很多事情 - 也許你可以自動化合並。
你真的需要做一個實際的合併,或者你想一起加入文件。這兩件事情完全不同。
當您有兩個版本的原始文件(可能存在衝突)更改時使用合併。我無法真正看到你將如何擁有需要將所有文件合併在一起的「大量」文件。這將是一場絕對的衝突噩夢。你的意思是把它們集合成單個文件嗎?
加入是當你想連接他們一個接一個。這會容易得多。這很可能使用COM API。
2
我偶然發現了Graham Skan的帖子。它可能讓你開始:
Sub InsertFiles()
Dim strFileName As String
Dim rng As Range
Dim Doc As Document
Const strPath = "C:\Documents and Settings\Graham Skan\My Documents\Allwork\" 'adjust as necessary '"
Set Doc = Documents.Add
strFileName = Dir$(strPath & "\*.doc")
Do
Set rng = Doc.Bookmarks("\EndOfDoc").Range
If rng.End > 0 Then 'section break not necessary before first document.'
rng.InsertBreak wdSectionBreakNextPage
rng.Collapse wdCollapseEnd
End If
rng.InsertFile strPath & "\" & strFileName
strFileName = Dir$()
Loop Until strFileName = ""
End Sub
相關問題
- 1. 將MS Word文檔與Java合併
- 2. 在github中合併MS Word文檔
- 3. (MS Word/VBA)當文檔打開時執行郵件合併
- 4. 合併多個xsd文件的工具
- 5. 工具合併3個CSS文件
- 6. 合併word文檔到單個文件
- 7. PHP MS Word文件頁數
- 8. 使用SQLite數據庫的MS Word郵件合併
- 9. 將數據庫中的HTML郵件合併到MS Word中
- 10. MS Word 2010中的郵件合併:動態URL,同樣的文字
- 11. 使用合併域從文本文件導入數據(MS Word 2010中)
- 12. 使用Firemonkey將數據與MS Word文檔合併
- 13. 在MS Word XML中多次運行中合併文本
- 14. 找到MS Word郵件合併數據源
- 15. 如何在MS Word中隱藏郵件合併行結果?
- 16. MS Word郵件合併,多列成行,動態表
- 17. Word/PDF - 合併文檔
- 18. 合併Word文檔C#
- 19. 執行Word郵件合併
- 20. ASP.NET Word郵件合併
- 21. Word郵件合併字段
- 22. SVN合併工具
- 23. Ms Word帶空格的文件名
- 24. 自動合併文本文件的工具?
- 25. 工具合併的Java bean
- 26. MS CRM郵件合併
- 27. 集成的MS Office工具,如Outlook,Word中等與CQ
- 28. 如何用php打開MS Word文件?
- 29. 在pywin32中打開MS Word文件
- 30. Java打印API。 MS Word文件
米奇,抱歉雙編輯。 SO的突出顯示模塊因VBA/VBS而出名。 +1將您排除在列表的末尾。 – Tomalak 2008-11-10 10:05:41
沒問題。我給你+1,因爲它是一個更好的代碼! – 2008-11-10 10:11:29