因為需要進行批處理翻譯,需要對特殊樣式的專業詞匯進行替換。于是我去錄制了宏,得到如下代碼
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Font.Bold = True
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Mercury Accumulation"
.Replacement.Text = "Mercury Accumulation^p汞元素聚積"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
Selection.Find.Execute
可問題是詞庫太大了,如果全部都寫如一個宏中,就無法執行,因為Office宏在編譯時,一個程序的代碼不得超過 6.4 萬個字符。
所以下一步是需要我把詞庫存在一個Excel表里,然后呼叫嗎?小白很迷茫
uj5u.com熱心網友回復:
放文本檔案也可以啊,一行行地讀入,處理,進行替換轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/22076.html
上一篇:想把某一個月份內改動過的檔案(包含windows下完整路徑) 修改時間保存到txt本中
下一篇:excel單元格字體顏色設定
