|
楼主 |
发表于 2016-11-24 15:54
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 ctp_119 于 2016-11-24 15:55 编辑
- Sub tiqu()
- On Error GoTo errorline
- Dim appword As Word.Application
- Dim doc As Word.Document
- Dim p As String
- Dim str As String
- Dim st As String
- Dim mytable As Table
- Dim irow As Integer
- Dim rngparagraph As Word.Range
- Application.ScreenUpdating = False
- irow = 2
- Range("a2:i999").ClearContents
- Set appword = GetObject(, "word.application")
- p = ThisWorkbook.Path
- str = Dir(p & "\*.doc")
- Do Until str = ""
- Set doc = appword.Documents.Open(p & "" & str, ConfirmConversions:=False, ReadOnly:= _
- False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _
- "", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="", _
- Format:=wdOpenFormatAuto, XMLTransform:="")
- Set rngparagraph = ActiveDocument.Paragraphs(2).Range
- st = rngparagraph.Text
- Set mytable = doc.Tables(1)
- Cells(irow, 1) = VBA.Trim$(Mid(st, 7, 7))
- Cells(irow, 2) = VBA.Trim$(mytable.Cell(3, 3).Range)
- Cells(irow, 3) = VBA.Trim$(Left(Right(st, 6), 5))
- Cells(irow, 4) = VBA.Trim$(mytable.Cell(15, 6).Range)
- Cells(irow, 5) = VBA.Trim$(mytable.Cell(16, 6).Range)
- Cells(irow, 6) = VBA.Trim$(mytable.Cell(20, 3).Range)
- Cells(irow, 7) = VBA.Trim$(mytable.Cell(23, 3).Range)
- doc.Close False
- irow = irow + 1
- str = Dir
- Loop
- errorexit:
- Application.ScreenUpdating = True
- Set appword = Nothing
- Exit Sub
- errorline:
- If Err.Number = 429 Then
- Set appword = CreateObject("word.application")
- Resume Next
- Else
- MsgBox "错误号:" & Err.Number & "错误提示:" & Err.Description
- Resume errorexit
- End If
-
- End Sub
复制代码 从word文档中提取数据到excel中的实例!!!
|
|