å
åä¸ä¸ªæ¿æ¢çå®ç»ä½ è¯è¯ï¼
Sub Replace()
Dim Message, Title, Default, MyValue, NeedReplace, MyReplace
Message = "请è¾å
¥æ件æå¨ç®å½" ' Set prompt.
Title = "InputBox Demo" ' Set title.
Default = "c:\" ' Set default.
' Display message, title, and default value.
MyValue = InputBox(Message, Title, Default)
Message = "请è¾å
¥éè¦è¢«æ¿æ¢çè¯" ' Set prompt.
Title = "InputBox Demo" ' Set title.
Default = "aaa" ' Set default.
' Display message, title, and default value.
NeedReplace = InputBox(Message, Title, Default)
Message = "请è¾å
¥æ¿æ¢ä¹åçè¯" ' Set prompt.
Title = "InputBox Demo" ' Set title.
Default = "xxx" ' Set default.
' Display message, title, and default value.
MyReplace = InputBox(Message, Title, Default)
Dim MyFoundFiles(10000)
Dim MyFoundCount
With Application.FileSearch
.FileName = "*.txt"
.LookIn = MyValue
.Execute
MyFoundCount = .FoundFiles.Count
For i = 1 To .FoundFiles.Count
MyFoundFiles(i) = .FoundFiles(i)
Next i
End With
For i = 1 To MyFoundCount
Documents.Open FileName:=MyFoundFiles(i)
With Selection.Find
.Text = NeedReplace
.Replacement.Text = MyReplace
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Documents(MyFoundFiles(i)).Save
ActiveWindow.Close
Next i
End Sub
温馨提示:答案为网友推荐,仅供参考