|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Explicit
Sub test()
Dim ar(), i&, r&, wdApp As Word.Application, strFileName$, strPath$, strSaveName$
strPath = ThisWorkbook.Path & "\"
strFileName = strPath & "模板.docx"
If Dir(strFileName) = "" Then MsgBox "模板文件不存在,请检查!", vbExclamation: Exit Sub
Application.ScreenUpdating = False
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err <> 0 Then
Set wdApp = New Word.Application
End If
With wdApp.documents.Open(strFileName)
strSaveName = strPath & "模板(希望达到的效果)"
With .Content.Find
.ClearFormatting
.Forward = True
Do While .Execute(FindText:="此行删除") = True
.Parent.Select
With wdApp.Selection
If .Information(wdWithInTable) = True Then
.selectRow
r = r + 1
ReDim Preserve ar(1 To r)
Set ar(r) = .Range
End If
End With
Loop
End With
For i = 1 To UBound(ar)
ar(i).Rows.Delete
Next i
.SaveAs strSaveName
.Close
End With
If Err <> 0 Then wdApp.Quit
Set wdApp = Nothing
Application.ScreenUpdating = True
Beep
End Sub
|
评分
-
1
查看全部评分
-
|