|
Option Explicit
Sub test()
Dim wdApp As Object, strFileName$, strPath$
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 = CreateObject("Word.Application")
End If
With wdApp.documents.Open(strFileName)
With .Content.Find
.Text = "主 题:"
.Forward = True
.Execute
If .Found = True Then
.Parent.Select
With wdApp.Selection.Range
.MoveEndUntil vbCr
.Text = "主 题:我的家乡" & " 周 次:第7周"
End With
End If
End With
.Close True
End With
If Err <> 0 Then wdApp.Quit
Set wdApp = Nothing
Application.ScreenUpdating = True
Beep
End Sub
|
|