在有word文件的文件夹中新建一个excel工作簿,打开工作簿,按alt+f11,把下面的代码复制进去,按f5执行。
代码会复制work文件的前300个字符到excel中。
sub test()
dim i%, myname$, mypath$, appword as object
set appword = createobject("word.application")
mypath = thisworkbook.path & ""
myname = dir(mypath & "*.doc*")
with activesheet
.columns("a:b").clearcontents
do while myname <> ""
appword.documents.open filename:=mypath & myname
i = i + 1
.cells(i, 1) = myname
.cells(i, 2) = appword.activedocument.range(start:=0, end:=300).text
appword.activedocument.close false
myname = dir
loop
end with
appword.quit
set appword = nothing
msgbox "已完成。"
end sub