Office中国论坛/Access中国论坛
标题:
多种内容同时替换
[打印本页]
作者:
zhuzz
时间:
2010-7-30 17:41
标题:
多种内容同时替换
在word中有一替换功能,可以实现将某一内容批量替换为另一内容。如果要实现多个内容的同时替换。即A替换成B,同时,C替换为D,E替换为F应该如何实现呢?也就是通过某一功能(应该是宏吧?!)对文档内容进行规范化设置。有高手的帮忙请答一下,不胜感谢!!
作者:
tmtony
时间:
2010-7-30 20:57
可以用宏或者VBA
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "A"
.Replacement.Text = "B"
.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.Find
.Text = "C"
.Replacement.Text = "D"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
作者:
zhuzz
时间:
2010-7-31 19:01
网上出现的,我自己作了一些修改
Sub ToggleInterpunction() '
Dim ChineseInterpunction() As Variant, EnglishInterpunction() As Variant
Dim myArray1() As Variant, myArray2() As Variant, strFind As String, strRep As String
Dim msgResult As VbMsgBoxResult, N As Byte
'
ChineseInterpunction = Array("1 mol", "=", ",", ";", "∶", "+", "∶", "!", "……", "-", "~", "(", ")", "<", ">", "A.", "B.", "C.", "D.", "A.", "B.", "C.", "D.", "A.", "B.", "C.", "D.", "1.", "2.", "3.", "4.", "5.", "6.", "7.", "8.", "9.", "0.", "1 g", "2 g", "3 g", "4 g", "5 g", "6 g", "7 g", "8 g", "9 g", "0 g", "b g", "c g", "1 mL", "2 mL", "3 mL", "4 mL", "5 mL", "6 mL", "7 mL", "8 mL", "9 mL", "0 mL", "a mL", "b mL", "c mL", "1 L", "2 L", "3 L", "4 L", "5 L", "6 L", "7 L", "8 L", "9 L", "0 L", "b L", "c L", "2 mol", "3 mol", "4 mol", "5 mol", "6 mol", "7 mol", "8 mol", "9 mol", "0 mol", "a mol", "b mol", "c mol", " ℃")
'
EnglishInterpunction = Array("1mol", "=", ",", ";", ":", "+", ":", "!", "…", "-", "~", "(", ")", "<", ">", "A.", "B.", "C.", "D.", "A. ", "B. ", "C. ", "D. ", "A、", "B、", "C、", "D、", "1、", "2、", "3、", "4、", "5、", "6、", "7、", "8、", "9、", "0、", "1g", "2g", "3g", "4g", "5g", "6g", "7g", "8g", "9g", "0g", "bg", "cg", "1mL", "2mL", "3mL", "4mL", "5mL", "6mL", "7mL", "8mL", "9mL", "0mL", "amL", "bmL", "cmL", "1L", "2L", "3L", "4L", "5L", "6L", "7L", "8L", "9L", "0L", "bL", "cL", "2mol", "3mol", "4mol", "5mol", "6mol", "7mol", "8mol", "9mol", "0mol", "amol", "bmol", "cmol", "℃")
myArray1 = EnglishInterpunction
myArray2 = ChineseInterpunction
strFind = """(*)"""
For N = 0 To UBound(ChineseInterpunction) '从数组的下标到上标间作一个循环
With ActiveDocument.Content.Find
.ClearFormatting '不限定查找格式
.MatchWildcards = False '不使用通配符
.Execute findtext:=myArray1(N), replacewith:=myArray2(N), Replace:=wdReplaceAll
End With
Next
With ActiveDocument.Content.Find
.ClearFormatting '不限定查找格式
.MatchWildcards = True '使用通配符
.Execute findtext:=strFind, replacewith:=strRep, Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True '恢复屏幕更新
End Sub
作者:
zhuzz
时间:
2010-7-31 19:05
能不能看看,哪些可以不要的,谢谢了。这种替换只能将原来的字符替换成另外形式的字符,但是没有我想有要格式。如果我现在需要将原来的某种格式替换成另外一种格式,如将两个正常的字符替换成第一个是加粗的斜体、第二个下标,这样的替换如何实现呢?
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3