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

看板Visual_Basic作者 (沒有存在感的人)時間3年前 (2021/03/18 21:23), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
由於要處理古早的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 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 86.220.55.131 (法國) ※ 文章網址: https://www.ptt.cc/bbs/Visual_Basic/M.1616073783.A.D24.html
文章代碼(AID): #1WKrGtqa (Visual_Basic)