帮忙改改这个

来源:百度知道 编辑:UC知道 时间:2024/06/06 07:50:42
Private Sub Command1_Click()
Dim wordObj
Set wordObj = CreateObject("Word.Application")
With wordObj.Documents.Open("c:\1.doc")'WORD文档路径
With .Content
If .Find.Execute("ask") Then
.Text = Me.Text1.Text
End If
End With
.Save
End With
wordObj.quit
End Sub

如题上面有一段代码........
麻烦帮我小改一下.......或改一个类似功能的
因为在WORD文档中有若干个"ASK"....
所以要把这段东西改成可以一次替换全部"ASK"的
完成后另存到D盘

我的邮箱:
fly1987abc@hotmail.com
如果在文件里面还有一个要改的
如:ABC...改为TEXT2的内容
应该怎么加上去呢.....

Private Sub Command1_Click()
Dim wrdApp, S As String
Set wrdApp = CreateObject("Word.application")
With wrdApp
.DisplayAlerts = False
'.Visible = True
.Documents.Open "c:\1.doc" '请修改为具体的文件名
.Selection.Find.ClearFormatting
.Selection.Find.Replacement.ClearFormatting
With .Selection.Find
.Text = "ask" '查找的字符串
.Replacement.Text = Me.Text1.Text '要替换的字符串
.Forward = True
.Wrap = 1
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
.Selection.Find.Execute Replace:=2
.ActiveDocument.SaveAs "d:\1.doc" '文件另存
.Documents.Close
.Quit
End With
Set wrdApp = Nothing
MsgBox &quo