|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
我现在有一个文件夹里面有许多名字没有规律的word文件,该文件夹好比是 C:\Documents and Settings\Administrator\桌面\新建文件夹,我现在在这个文件夹中的一个word中做了一个宏,也就是定位到第四页,然后查找到1,之后改为2,再次查找到的1改为空,然后再次定位到第四页,查找 临沧 这两个字,改为 昆明 ,然后就是保存。我现在想要这个宏自动对该文件夹下面的所有文件运行一次,请问版主,该如何解决啊,因为我一点都不懂得vba,所以恳请版主帮忙写一下啊,上千个文件需要这么操作啊。急盼。
下面是我用录制的宏代码:
- Sub 替换()
- '
- ' 替换 宏
- '
- '
- Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="4"
- Selection.Find.ClearFormatting
- Selection.Find.Replacement.ClearFormatting
- With Selection.Find
- .Text = "1"
- .Replacement.Text = "2"
- .Forward = True
- .Wrap = wdFindContinue
- .Format = False
- .MatchCase = False
- .MatchWholeWord = False
- .MatchByte = True
- .MatchWildcards = False
- .MatchSoundsLike = False
- .MatchAllWordForms = False
- End With
- Selection.Find.Execute
- With Selection
- If .Find.Forward = True Then
- .Collapse Direction:=wdCollapseStart
- Else
- .Collapse Direction:=wdCollapseEnd
- End If
- .Find.Execute Replace:=wdReplaceOne
- If .Find.Forward = True Then
- .Collapse Direction:=wdCollapseEnd
- Else
- .Collapse Direction:=wdCollapseStart
- End If
- .Find.Execute
- End With
- With Selection.Find
- .Text = "1"
- .Replacement.Text = ""
- .Forward = True
- .Wrap = wdFindContinue
- .Format = False
- .MatchCase = False
- .MatchWholeWord = False
- .MatchByte = True
- .MatchWildcards = False
- .MatchSoundsLike = False
- .MatchAllWordForms = False
- End With
- With Selection
- If .Find.Forward = True Then
- .Collapse Direction:=wdCollapseStart
- Else
- .Collapse Direction:=wdCollapseEnd
- End If
- .Find.Execute Replace:=wdReplaceOne
- If .Find.Forward = True Then
- .Collapse Direction:=wdCollapseEnd
- Else
- .Collapse Direction:=wdCollapseStart
- End If
- .Find.Execute
- End With
- Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="4"
- With Selection.Find
- .Text = "临沧"
- .Replacement.Text = "昆明"
- .Forward = True
- .Wrap = wdFindContinue
- .Format = False
- .MatchCase = False
- .MatchWholeWord = False
- .MatchByte = True
- .MatchWildcards = False
- .MatchSoundsLike = False
- .MatchAllWordForms = False
- End With
- Selection.Find.Execute
- With Selection
- If .Find.Forward = True Then
- .Collapse Direction:=wdCollapseStart
- Else
- .Collapse Direction:=wdCollapseEnd
- End If
- .Find.Execute Replace:=wdReplaceOne
- If .Find.Forward = True Then
- .Collapse Direction:=wdCollapseEnd
- Else
- .Collapse Direction:=wdCollapseStart
- End If
- .Find.Execute
- End With
- ActiveDocument.Save
- End Sub
复制代码
|
|