|
利用Word中的“替换”功能,处理金山词霸生词本导出的单词
金山词霸生词本导出的内容:
【示例】
+separating
\分开[离, 裂]的
&5sepEreitiN
+selection
\n.选择, 挑选, 选集, 精选品
&si5lekFEn
运行宏后:
【效果】
separating 分开[离, 裂]的 ['sepəreitiŋ]
selection n.选择, 挑选, 选集, 精选品 [si'lek∫ən]
【说明】
1、为了处理最后一个音标的“]”需在文本最后一行添加“+”
+separating
\分开[离, 裂]的
&5sepEreitiN
+selection
\n.选择, 挑选, 选集, 精选品
&si5lekFEn
+
2、程序运行后需要点击“是”(确定替换)。
【代码】
'------------------------------
Sub Kingword()
'文档左对齐
Selection.WholeStory
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
'设置"Book Antiqua"字体
Selection.WholeStory
Selection.Font.Name = "Book Antiqua"
Selection.Font.Size = 9
'去除\并将单词解释移动单词后
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p\"
.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 Replace:=wdReplaceAll
'将音标移到解释的最后面
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p&"
.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 Replace:=wdReplaceAll
For i = 1 To 2000 '一次处理2000个单词
Phonetic
Next i
'在音标后加上"]"
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p+"
.Replacement.Text = "]^p"
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
'去除第一个“+”
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "+"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
'将页面分两栏
Selection.WholeStory
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type <> wdPrintView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
With Selection.PageSetup.TextColumns
.SetCount NumColumns:=2
.EvenlySpaced = True
.LineBetween = False
End With
'设置页边距
WordBasic.PageSetupMargins Tab:=0, PaperSize:=0, TopMargin:="2", _
BottomMargin:="2", LeftMargin:="2", RightMargin:="2", Gutter:="0", _
PageWidth:="21", PageHeight:="29.7", Orientation:=0, FirstPage:=0, _
OtherPages:=0, VertAlign:=0, ApplyPropsTo:=4, FacingPages:=0, _
HeaderDistance:="1.5", FooterDistance:="1.75", SectionStart:=2, _
OddAndEvenPages:=0, DifferentFirstPage:=0, Endnotes:=0, LineNum:=0, _
CountBy:=0, TwoOnOne:=0, GutterPosition:=0, LayoutMode:=2, DocFontName:= _
"", FirstPageOnLeft:=0, SectionType:=1, FolioPrint:=0, ReverseFolio:=0, _
FolioPages:=1
'去除'[" & ChrW(61533)'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "[" & ChrW(61533)
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Sub Phonetic()
Selection.Find.ClearFormatting '查找第一个字符是"&"的行
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
If Selection.Characters.First.Text <> "&" Then
Exit Sub '无“&”跳出循环
End If
Selection.Delete Unit:=wdCharacter, Count:=1 '删除"&"字符
Char = Selection.MoveEndUntil(cset:=vbCr, Count:=100) '选中这一行余下的内容
Selection.Font.Name = "Kingsoft Phonetic Plain" '设置字体
End Sub
'----------------------------
【参考】
Phonetic()函数:http://blog.csdn.net/l1t/archive/2004/07/22/48395.aspx |
|