删除Word VBA中的特殊字符

时间:2015-10-02 13:40:15

标签: vba special-characters word-vba

我正在尝试创建一个宏来删除Word文档中的所有特殊字符,我对工作中需要删除的所有特殊字符的基本引用是:

特殊字符

•生产时间

(8CCR§9792.24.3),

μ('u'不是一个字母,它实际上是一个符号'μ')如果它在文件中记录为“μgm”,并且评论者将其命令为“每克单位”,那么放置单位每克(注意文件状态μgm[microgram / mcg])。

月骨无菌性坏死的

·疼痛干扰...

®

©

·疼痛干扰...

*术后物理

拮抗剂,α-肾上腺素能,胆碱能受体激动剂,γ激动剂,Voltaren®凝胶

•基因型1

治疗初治

≥(添加到自动更正=大于或等于)

在上面的文字中找到的任何特殊字符都是我在任何给定时间从我的Word文档中删除的内容,或者替换为它们各自的含义& =和,μ=微等我试过研究,看看有没有,但我似乎找不到任何东西。我真的没有设定代码,因为我是一个真正的新手。任何有关这方面的帮助将不胜感激。这将在Word 2013或2007中,因为我也会为我的同事发送此宏。

1 个答案:

答案 0 :(得分:0)

试试这个,我知道它已经很久了,但就你所要求的而言,它似乎也完成了我的工作

Sub SpecChar()
'
' SpecChar Macro

Dim oPara As Paragraph
For Each oPara In ActiveDocument.Paragraphs()
        Set r = oPara.Range
        If r.ListFormat.ListType = wdListBullet Then
            r.ListFormat.RemoveNumbers
            End If

        Set r = Nothing
Next

   Selection.Find.ClearFormatting
   Selection.Find.Replacement.ClearFormatting
   With Selection.Find
      .Text = "§"
      .Replacement.Text = ""
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = True
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
   With Selection.Find
      .Text = "&"
      .Replacement.Text = "and"
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = True
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
   With Selection.Find
      .Text = "µ"
      .Replacement.Text = "micro"
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = True
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
   With Selection.Find
      .Text = "°"
      .Replacement.Text = " degrees"
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = True
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
   With Selection.Find
      .Text = "±"
      .Replacement.Text = "plus/minus "
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = True
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
   With Selection.Find
      .Text = "®"
      .Replacement.Text = ""
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = True
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
   With Selection.Find
      .Text = "©"
      .Replacement.Text = ""
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = True
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
   With Selection.Find
      .Text = "™"
      .Replacement.Text = ""
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = True
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
    With Selection.Find
      .Text = ChrW(945)
      .Replacement.Text = "alpha"
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = True
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
   With Selection.Find
      .Text = ChrW(947)
      .Replacement.Text = "y"
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = True
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
   With Selection.Find
      .Text = ChrW(8804)
      .Replacement.Text = "less than or equal to "
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = True
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
   With Selection.Find
      .Text = ChrW(8805)
      .Replacement.Text = "greater than or equal to "
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = True
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
     .MatchAllWordForms = False
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
   With Selection.Find
      .Text = "*"
      .Replacement.Text = ""
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = True
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
   With Selection.Find
      .Text = "ö"
      .Replacement.Text = "o"
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = True
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
   With Selection.Find
      .Text = "æ"
      .Replacement.Text = "ae"
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = True
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
   With Selection.Find
      .Text = "ä"
      .Replacement.Text = "a"
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = True
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
   With Selection.Find
      .Text = "ï"
      .Replacement.Text = "i"
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = True
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
   End With
   Selection.Find.Execute Replace:=wdReplaceAll
   Selection.Find.ClearFormatting
   Selection.Find.Replacement.ClearFormatting

   With Selection.Find
      .Text = "[®§™©·†o·]"
      .Replacement.Text = ""
      .Forward = True
      .Wrap = wdFindStop
      .Format = False
      .MatchWildcards = True
   End With




End Sub