|
- Sub Word操控Excel()
- Dim pa As Paragraph, myBook As Object, mysheet As Object
- Dim RegMatch, n As Long, arrData(1 To 10000, 1 To 1)
- Application.ScreenUpdating = False
- With CreateObject("VBScript.Regexp")
- .Global = True: .MultiLine = True
- .Pattern = "(?:^|[,。?!:])([^,。?!:\r]*\d+[^,。?!:\r]*)"
- For Each pa In ActiveDocument.Paragraphs
- If Not pa.Range.Information(wdWithInTable) Then
- For Each RegMatch In .Execute(pa.Range.Text)
- n = n + 1
- arrData(n, 1) = RegMatch.submatches(0)
- Next
- End If
- Next
- End With
- With CreateObject("Excel.Application")
- If Tasks.Exists("Microsoft Excel") = True Then Tasks("Microsoft Excel").Close
- Set myBook = .Workbooks.Add: .Visible = True
- Set mysheet = myBook.Worksheets("sheet1"): mysheet.Activate
- mysheet.Range("a1").Resize(10000, 1) = arrData
- End With
- Set RegMatch = Nothing
- Set myBook = Nothing: Set mysheet = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|