<editBox id="layout_deck_search_replace_locate_Caption_item"
label="Caption Item"
showLabel="false"
sizeString="xxx"
maxLength="3"
onChange="layout_search_replace.jump_to_caption_item" />
Sub jump_to_caption_item(ByVal control As IRibbonControl, ByRef strText)
selection.collapse Direction:=wdCollapseEnd
a = "Figure " & Str(strText)
MsgBox a
With selection.Find
.Font.Bold = True
.Text = "Figure " & Str(strText)
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = False
.Replacement.Text = ""
.Execute
End With End Sub
上面是我的xml和vba代码,当我在编辑框中写“1”时,我想找到图1
当我在编辑框中写“1”时,msgbox可以“图1”,但我的单词不能转到“图1”。因为“图”&Str(strText)不是字符串?
下面的代码将在标题中找到数字。您可能需要调整它以找到找到该数字的图片。
Private Sub GoToFigure(ByVal Num As Integer)
' 27 Dec 2017
Dim Fld As Field
For Each Fld In ActiveDocument.Fields
With Fld
If (.Type = wdFieldSequence) And _
(InStr(1, .Code, "figure", vbTextCompare) > 0) Then
If .Result = Num Then
.Select
End If
End If
End With
Next Fld
End Sub
Sub的参数Num
是您要查找的标题的编号。用这样的代码调用sub。
GoToFigure 1
其中“1”是EditBox中的数字。