设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 3837|回复: 3
打印 上一主题 下一主题

多种内容同时替换

[复制链接]
跳转到指定楼层
1#
发表于 2010-7-30 17:41:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在word中有一替换功能,可以实现将某一内容批量替换为另一内容。如果要实现多个内容的同时替换。即A替换成B,同时,C替换为D,E替换为F应该如何实现呢?也就是通过某一功能(应该是宏吧?!)对文档内容进行规范化设置。有高手的帮忙请答一下,不胜感谢!!
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅

点击这里给我发消息

2#
发表于 2010-7-30 20:57:08 | 只看该作者
可以用宏或者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
3#
 楼主| 发表于 2010-7-31 19:01:52 | 只看该作者
网上出现的,我自己作了一些修改
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
4#
 楼主| 发表于 2010-7-31 19:05:17 | 只看该作者
能不能看看,哪些可以不要的,谢谢了。这种替换只能将原来的字符替换成另外形式的字符,但是没有我想有要格式。如果我现在需要将原来的某种格式替换成另外一种格式,如将两个正常的字符替换成第一个是加粗的斜体、第二个下标,这样的替换如何实现呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-29 16:48 , Processed in 0.083737 second(s), 27 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表