|
Public Sub zd()
Dim doc As Object
Dim abc As Object
FileDir = "e:\桌面文件\协议.doc"
On Error Resume Next
Set doc = GetObject(, "word.Application") '判断word是否打开
If Err.Number <> 0 Then
Set doc = CreateObject("word.Application") '创建word对象
doc.Visible = True '设置word对象可见
End If
Err.Clear
Set abc = doc.Documents.Open(FileDir) '打开word文件
abc.Visible = True
abc.Words(1).Select
With abc.Selection.Find '将@1替换成123
.ClearFormatting
.Text = "@1"
.Replacement.ClearFormatting
.Replacement.Text = "123"
.Execute Replace:=wdReplaceAll, Forward:=True, _
Wrap:=wdFindContinue
End With
End Sub
|
|