|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Explicit
Sub test()
Dim wdApp As Word.Application, strPlanName$, strExecuteName$
Dim ar, br$(), i&, j&, r&, strPath$, regEx As Object, Par As Word.Paragraph
strPath = ThisWorkbook.Path & "\"
strPlanName = strPath & "计划表.docx"
If Dir(strPlanName) = "" Then MsgBox "计划表不存在,请检查!", vbExclamation: Exit Sub
strExecuteName = strPath & "执行表.docx"
If Dir(strExecuteName) = "" Then MsgBox "执行表不存在,请检查!", vbExclamation: Exit Sub
Application.ScreenUpdating = False
ar = Array("电焊", "机修", "抛光")
Set regEx = CreateObject("VBScript.RegExp")
regEx.Pattern = "[一二三四五六七八九十]+、"
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err <> 0 Then
Set wdApp = New Word.Application
End If
With wdApp.documents.Open(strPlanName)
For Each Par In .Paragraphs
If regEx.test(Par.Range.Text) Then
With Par.Range
.Select
.End = .End - 1
r = r + 1
ReDim Preserve br(1 To 2, 1 To r)
br(1, r) = Replace(.Text, regEx.Execute(.Text)(0).Value, "")
With wdApp.Selection
.MoveDown unit:=wdLine
.MoveUp unit:=wdParagraph, Extend:=wdExtend
.MoveEndUntil vbCr
br(2, r) = .Text
End With
End With
End If
Next
.Close False
End With
With wdApp.documents.Open(strExecuteName)
For j = 1 To UBound(br, 2)
With .Content.Find
.Text = br(1, j)
.Forward = True
.Execute
If .Found = True Then
.Parent.Select
With wdApp.Selection
.MoveDown unit:=wdLine
.MoveUp unit:=wdParagraph, Extend:=wdExtend
.MoveEndUntil vbCr
.Range.Text = br(2, j)
End With
End If
End With
Next j
.Close True
End With
If Err <> 0 Then wdApp.Quit
Set wdApp = Nothing
Application.ScreenUpdating = True
Beep
End Sub
|
评分
-
1
查看全部评分
-
|