|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
既然是在Word板块的帖子,我就用WordVBA写个代码!- Sub main()
- Dim myDaTa(), doc As Document, pf$, xlapp As Object
- Set doc = ActiveDocument
- ReDim myDaTa(1 To 1, 1 To 2)
- Call GetDaTa(doc, myDaTa)
- pf = doc.Path & "\文档2.xlsx"
- Set xlapp = CreateObject("Excel.Application")
- xlapp.Visible = True
- With xlapp.Workbooks.Open(pf)
- .sheets(1).Cells.Clear
- .sheets(1).[a1] = "标题": .sheets(1).[b1] = "内容"
- .sheets(1).Range("a2").Resize(UBound(myDaTa), 2) = myDaTa
- End With
- MsgBox "OK!"
- End Sub
- Sub GetDaTa(thisdoc As Document, ByRef p)
- Dim ar(), n&, i&
- With thisdoc.Range.Find
- .ParagraphFormat.OutlineLevel = 1
- Do While .Execute
- With .Parent
- n = n + 1: ReDim Preserve ar(n)
- ar(n - 1) = .Start: .Start = .End
- End With
- Loop
- End With
- ar(n) = thisdoc.Range.End: ReDim p(1 To n, 1 To 2)
- For i = 1 To n
- With thisdoc.Range(ar(i - 1), ar(i))
- p(i, 1) = .Paragraphs(1).Range.Text
- .MoveStart 4, 1
- p(i, 2) = .Text
- End With
- Next
- End Sub
复制代码 |
评分
-
2
查看全部评分
-
|