[VBA ] 希望把搜尋到的字去掉一部分再改層級

作者: wtchen (沒有存在感的人)   2021-03-18 21:23:01
由於要處理古早的latex檔案,裡面一堆標籤(呈\abcd{defg}狀)
想寫個巨集處理各種標籤,這樣方便轉Word。
以下是想將以\chapter{abcd}形式出現的文字處理掉:
- 去掉\chapter{},只保留abcd
- 將abcd變成大綱模式中的階層一
我現在卡在如何將Selection.Find找到的字串傳給此函式,
然後用此函式輸出的結果來取代原字串。
程式碼如下:
'將\chapter{abcd}變成abcd的函式
'其中str_orig為"\chapter{"或其他字串'
輸出結果變abcd
Function treat_string(str_orig, str_cut)
Dim size_str_cut As Integer
Dim str_cut_1 As String
size_str_cut = strLen(str_cut)
str_cut_1 = Left(str_orig, size_str_cut)
treat_string = Right(str_cut_1, 1)
End Function
Sub search_all()
'
With Selection.Find
.ClearFormatting
.MatchAllWordForms = False
.Text = "\\chapter\{*\}"
.MatchSoundsLike = False
.MatchFuzzy = False
.MatchWildcards = True
' .Execute Format:=False, Forward:=True
With .Replacement
.Text = "End" ' ==>如何把前面定義的函式放在這邊?
End With
.Execute Replace:=wdReplaceAll
End With
End Sub
謝謝

Links booklink

Contact Us: admin [ a t ] ucptt.com