[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