我的目标是创建一个包含两个SEQIdentifiers的TOC 它被描述和回答HERE,虽然给出的答案是手动配置的,我想用宏来激活它。
简要说明
我在整个文件中有一个连续的数字,可以用数字表{SEQ \c "Figure"}
收集
图结构如下:
Figure {STYLEREF 1 \s}-{SEQ Figure \*Arabic \s 1}
- 结果以“图1-1”为例。
客户端请求是添加“Point Figure”,意思是两个数字之间:图1-1和图1-2客户端可以添加图1-1.A,图1-1.B等。<登记/>
以下是我最初创建结构的方式:
Figure {STYLEREF 1 \s}-{SEQ Figure \*Arabic \c}.{SEQ PointFigure \* Alphabetic \s 1}
。
现在的问题是我不能将它们都包含在一个数据表中。
尝试实施给定答案:
所以,我的下一个方法是开始实现上面链接中给出的答案
顺便给出的答案如下:
{ SEQ Table \r { REF tablea } }
这是我的代码,然后是解释和我的问题:
Sub createPointFigure()
Dim rng As Range
Dim fld As Field
Dim searchText As String
Set rng = Selection.Range
rng.InsertAfter "Figure "
rng.Collapse wdCollapseEnd
Set fld = rng.Fields.Add(rng, wdFieldEmpty, "StyleRef 1 \s", False)
Set rng = fld.result
'Move focus after the inserted field
rng.Collapse wdCollapseEnd
rng.MoveStart wdCharacter, 1
rng.InsertAfter "-"
rng.Collapse wdCollapseEnd
rng.Fields.Add rng, wdFieldEmpty, "SEQ Figure \c", False
' select the entire inserted text
Selection.MoveRight wdWord, 4, wdExtend
searchText = Selection.Text
Set rng = Selection.Range
' Search for the specific figure in text
Selection.Collapse wdCollapseStart
Dim found As Boolean
found = False
While Not found And Selection.Start <> 1
findText searchText, False
For Each fld In Selection.Fields
If fld.Type = wdFieldSequence Then
' look for the original seq field
If InStr(1, fld.Code.Text, "\s 1", vbTextCompare) Then
found = True
Exit For
End If
End If
Next fld
If found Then
ActiveDocument.Bookmarks.Add Selection.Text, Selection
Else
' Collapse to the beginning and keep looking for the next one
Selection.Collapse wdCollapseStart
End If
Wend
End Sub
findText方法:
Sub findText(searchParam As String, forwardDirection)
With Selection.find
.ClearFormatting
.Text = searchParam
.Forward = forwardDirection
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute
End With
End Sub
解释
\c
的序列字段。)问题
ActiveDocument.Bookmarks.Add Selection.Text, Selection
感谢。
答案 0 :(得分:2)
感谢@CindyMeister的指导,这是我的问题的优雅答案。
点图配置:
Figure {STYLEREF 1 \s}-{SEQ Figure \c}.{SEQ PointFigure \* Alphabetic \s 1}. Figure Text *Style Separator* {TC "{STYLEREF "Figure Title"}" \f F}
数据表配置:
{TOC \f F \c "Figure"}
备注:
{TC}
必须具有不同的样式才能使STYLEREF正常工作
为此,我使用了Style Separator(Ctrl + Alt + Return)。字符样式是我认为的另一种选择。{SEQ PointFigure \h \r 0}