當前位置:編程學習大全網 - 網站源碼 - 如何用VBA宏程序將excel中的內容批量復制到word文檔中去

如何用VBA宏程序將excel中的內容批量復制到word文檔中去

抱歉,沒有實際調試代碼

DIR函數只返回文件名,不包含完整路徑

所以請重新修改為以下代碼:

Sub abc()

Dim App, WrdDoc, MyPath, MyFile, BM, Str

Mypath = "文件實際路徑" '請修改實際儲存路徑!

Set App = CreateObject("Word.Application") '用Set關鍵字創建Word應用成序對象!

MyFile = Dir(Mypath & "\*.doc") ' 獲得第壹個WORD文檔

do while MyFile <> "" ' 遍歷Mypath下面的所有WORD文檔

App.Visible = True

Set WrdDoc = App.Documents.Open(Mypath & "\" & MyFile) '打開這個Word文件!

for each BM in WrdDoc.Bookmarks ' 遍歷文檔中的所有書簽

Str = BM.Range ' 讀取書簽內容

next BM

WrdDoc.Close ' 關閉文件

MyFile = Dir ' 下壹個WORD文檔

Loop

Set App = Nothing

End Sub

  • 上一篇:www.onecoin.eu維卡幣怎樣登陸註冊
  • 下一篇:打開人人 總是出來 welcome to nginx!!怎麽解決!!!!!
  • copyright 2024編程學習大全網