vbaword调用excelvbaword调用excel
发布网友
发布时间:2024-07-27 13:01
我来回答
共1个回答
热心网友
时间:2024-07-27 13:24
在有word文件的文件夹中新建一个excel工作簿,打开工作簿,按Alt+F11,把下面的代码复制进去,按F5执行。代码会复制work文件的前300个字符到excel中。
Sub test()Dimi%, myName$, myPath$, AppWord As ObjectSet AppWord = CreateObject("Word.Application"
)myPath = ThisWorkbook.Path & "\\"myName = Dir(myPath & "*.doc*")With ActiveSheet.Columns("A:B").ClearContentsDo While myName > ""AppWord.Documents.Open Filename:=myPath & myNamei = i + 1.Cells(i, 1) = myName.Cells(i, 2) = AppWord.ActiveDocument.Range(Start:=0, End:=300).TextAppWord.ActiveDocument.Close FalsemyName = DirLoopEnd WithAppWord.QuitSet AppWord = NothingMsgBox "已完成。"End Sub