Sub Test()
Application.ScreenUpdating = False Dim MyPath As String, MyFile As String, iRow As Integer Dim wdApp As Word.Application, wdDoc As Word.Document, ws As Worksheet MyPath = "D:\LSC_Documents" '指定路径 Set wdApp = CreateObject("Word.Application") wdApp.Visible = False 'ChDir MyPath '进入指定目录 MyFile = Dir(MyPath & "\" & "*.doc") Set ws = Sheets.Add(Before:=Sheets(2)) '将新建工作表插入到第2张工作表之前。 iRow = 4 '从第4行开始粘贴数据 Do While MyFile <> "" '如果是文件夹,或者没有此文件,则会返回"" Set wdDoc = wdApp.Documents.Open(MyPath & "\" & MyFile) wdDoc.Content.Copy With ws .Range("A" & iRow).Select .Paste iRow = .Range("A65536:Z65536").End(xlUp).Row + 2 '表格之间空1行 End With wdDoc.Close True MyFile = Dir() Loop Application.ScreenUpdating = True wdApp.Quit Set wdApp = Nothing Set wdDoc = Nothing Set ws = Nothing End Sub |
|