|
139 和 shenghua8(升华)朋友讨论得很热烈!
139:有现成的宏《英文双引号转换为中文双引号》,但不保证配对。
另外,你关于文字中间有空格的问题,如果空格多,并且没必要保留空格的话,我有一个现成的宏《删除所有空格》,它的特点是:如果选定了文字区域,就删除选定区域内的所有空格;否则,没有选定文字的话,会选定文档中的全部文字(即全选),删除所有空格。——但其实,有些空格用此宏也未必能删除。
还有,昨晚我按你的要求用《数组》(这个我不太会,但觉得似乎可以)做了一个《批量替换》宏。还有,MS Gothic字体中的数目字符号,即黑圈123白圈一二三后面有若干空格也要加顿号的这个宏,我也重新编辑了一下,下面把 3 个宏都发上来,你复制到 VBE 中试试吧!
- Sub 删除所有空格()
- Dim myRange As Range
- If Selection.Type = wdSelectionIP Then Selection.WholeStory
- Set myRange = Selection.Range
- myRange.Find.Execute findtext:=" ", ReplaceWith:="", Replace:=wdReplaceAll '删除所有全角空格
- myRange.Find.Execute findtext:="^w", ReplaceWith:="", Replace:=wdReplaceAll '删除所有空白区域
- End Sub
- Sub 批量替换_数组()
- Dim a, b, i As Long
- a = Array("北京", "上海", "天津", "重庆", "沈阳", "大连", "广州")
- b = Array("BeiJing", "ShangHai", "TianJin", "ChongQing", "ShenYang", "DaLian", "GuangZhou")
- Do
- ActiveDocument.Content.Find.Execute findtext:=a(i), ReplaceWith:=b(i), Replace:=wdReplaceAll
- i = i + 1
- Loop Until i = 7
- End Sub
- Sub 黑圈123白圈一二三加顿号()
- Selection.HomeKey Unit:=wdStory
- Selection.Find.ClearFormatting
- Do While Selection.Find.Execute(findtext:=ChrW(10102), Forward:=True)
- Do
- Selection.MoveEnd Unit:=wdCharacter, Count:=1
- If Asc(Selection.Characters.Last) = 13 Then Exit Do
- Loop Until Selection.Characters.Last.Text <> ChrW(160) And Asc(Selection.Characters.Last) <> 9 And _
- Selection.Characters.Last Like "[! ]"
- Selection.MoveEnd Unit:=wdCharacter, Count:=-1
- Selection = Replace(Selection, ChrW(160), "")
- Selection = Replace(Selection, " ", "")
- Selection = Replace(Selection, " ", "")
- Selection = Replace(Selection, Chr(9), "")
- Selection.MoveEnd Unit:=wdCharacter, Count:=1
- If Selection.Characters.Last.Text = "、" Then
- Selection.Characters.Last.Delete
- Else
- Selection.MoveEnd Unit:=wdCharacter, Count:=-1
- End If
- Selection.InsertAfter Text:="、"
- Selection.MoveRight Unit:=wdCharacter, Count:=1
- Loop
- '
- Selection.HomeKey Unit:=wdStory
- Selection.Find.ClearFormatting
- Do While Selection.Find.Execute(findtext:=ChrW(10103), Forward:=True)
- Do
- Selection.MoveEnd Unit:=wdCharacter, Count:=1
- If Asc(Selection.Characters.Last) = 13 Then Exit Do
- Loop Until Selection.Characters.Last.Text <> ChrW(160) And Asc(Selection.Characters.Last) <> 9 And _
- Selection.Characters.Last Like "[! ]"
- Selection.MoveEnd Unit:=wdCharacter, Count:=-1
- Selection = Replace(Selection, ChrW(160), "")
- Selection = Replace(Selection, " ", "")
- Selection = Replace(Selection, " ", "")
- Selection = Replace(Selection, Chr(9), "")
- Selection.MoveEnd Unit:=wdCharacter, Count:=1
- If Selection.Characters.Last.Text = "、" Then
- Selection.Characters.Last.Delete
- Else
- Selection.MoveEnd Unit:=wdCharacter, Count:=-1
- End If
- Selection.InsertAfter Text:="、"
- Selection.MoveRight Unit:=wdCharacter, Count:=1
- Loop
- '
- Selection.HomeKey Unit:=wdStory
- Selection.Find.ClearFormatting
- Do While Selection.Find.Execute(findtext:=ChrW(10104), Forward:=True)
- Do
- Selection.MoveEnd Unit:=wdCharacter, Count:=1
- If Asc(Selection.Characters.Last) = 13 Then Exit Do
- Loop Until Selection.Characters.Last.Text <> ChrW(160) And Asc(Selection.Characters.Last) <> 9 And _
- Selection.Characters.Last Like "[! ]"
- Selection.MoveEnd Unit:=wdCharacter, Count:=-1
- Selection = Replace(Selection, ChrW(160), "")
- Selection = Replace(Selection, " ", "")
- Selection = Replace(Selection, " ", "")
- Selection = Replace(Selection, Chr(9), "")
- Selection.MoveEnd Unit:=wdCharacter, Count:=1
- If Selection.Characters.Last.Text = "、" Then
- Selection.Characters.Last.Delete
- Else
- Selection.MoveEnd Unit:=wdCharacter, Count:=-1
- End If
- Selection.InsertAfter Text:="、"
- Selection.MoveRight Unit:=wdCharacter, Count:=1
- Loop
- '
- Selection.HomeKey Unit:=wdStory
- Selection.Find.ClearFormatting
- Do While Selection.Find.Execute(findtext:=ChrW(12928), Forward:=True)
- Do
- Selection.MoveEnd Unit:=wdCharacter, Count:=1
- If Asc(Selection.Characters.Last) = 13 Then Exit Do
- Loop Until Selection.Characters.Last.Text <> ChrW(160) And Asc(Selection.Characters.Last) <> 9 And _
- Selection.Characters.Last Like "[! ]"
- Selection.MoveEnd Unit:=wdCharacter, Count:=-1
- Selection = Replace(Selection, ChrW(160), "")
- Selection = Replace(Selection, " ", "")
- Selection = Replace(Selection, " ", "")
- Selection = Replace(Selection, Chr(9), "")
- Selection.MoveEnd Unit:=wdCharacter, Count:=1
- If Selection.Characters.Last.Text = "、" Then
- Selection.Characters.Last.Delete
- Else
- Selection.MoveEnd Unit:=wdCharacter, Count:=-1
- End If
- Selection.InsertAfter Text:="、"
- Selection.MoveRight Unit:=wdCharacter, Count:=1
- Loop
- '
- Selection.HomeKey Unit:=wdStory
- Selection.Find.ClearFormatting
- Do While Selection.Find.Execute(findtext:=ChrW(12929), Forward:=True)
- Do
- Selection.MoveEnd Unit:=wdCharacter, Count:=1
- If Asc(Selection.Characters.Last) = 13 Then Exit Do
- Loop Until Selection.Characters.Last.Text <> ChrW(160) And Asc(Selection.Characters.Last) <> 9 And _
- Selection.Characters.Last Like "[! ]"
- Selection.MoveEnd Unit:=wdCharacter, Count:=-1
- Selection = Replace(Selection, ChrW(160), "")
- Selection = Replace(Selection, " ", "")
- Selection = Replace(Selection, " ", "")
- Selection = Replace(Selection, Chr(9), "")
- Selection.MoveEnd Unit:=wdCharacter, Count:=1
- If Selection.Characters.Last.Text = "、" Then
- Selection.Characters.Last.Delete
- Else
- Selection.MoveEnd Unit:=wdCharacter, Count:=-1
- End If
- Selection.InsertAfter Text:="、"
- Selection.MoveRight Unit:=wdCharacter, Count:=1
- Loop
- '
- Selection.HomeKey Unit:=wdStory
- Selection.Find.ClearFormatting
- Do While Selection.Find.Execute(findtext:=ChrW(12930), Forward:=True)
- Do
- Selection.MoveEnd Unit:=wdCharacter, Count:=1
- If Asc(Selection.Characters.Last) = 13 Then Exit Do
- Loop Until Selection.Characters.Last.Text <> ChrW(160) And Asc(Selection.Characters.Last) <> 9 And _
- Selection.Characters.Last Like "[! ]"
- Selection.MoveEnd Unit:=wdCharacter, Count:=-1
- Selection = Replace(Selection, ChrW(160), "")
- Selection = Replace(Selection, " ", "")
- Selection = Replace(Selection, " ", "")
- Selection = Replace(Selection, Chr(9), "")
- Selection.MoveEnd Unit:=wdCharacter, Count:=1
- If Selection.Characters.Last.Text = "、" Then
- Selection.Characters.Last.Delete
- Else
- Selection.MoveEnd Unit:=wdCharacter, Count:=-1
- End If
- Selection.InsertAfter Text:="、"
- Selection.MoveRight Unit:=wdCharacter, Count:=1
- Loop
- End Sub
复制代码 |
|