|
本帖最后由 kerry786032 于 2017-10-24 18:06 编辑
正确的引用顺序应该是,table1,2,3,4。如果table2出现在table1前面了,就要报错,但即使table 第一次引用是table 2,但如果table 1后面还出现了table 2,也不用给第一处的table 2 报错
同理类推其他table 3 4 ...
但如果table 2只出现在table 1前面,table 1后面一次也没出现,那么需要报错:在table 2第一处: Table 2 should be cited after Table 1.
同理
table 3 也必须要在table 2后面出现,如果table 2 后面一次也没出现table 3,那么需要在table 3第一处: Table 3 should be cited after Table 2.
下面是我写的代码,请老师帮忙修改下,谢谢。
Sub table_order()
Dim last_called As Integer, reference_by_numbered_list As Integer
last_called = 0
selection.Find.Font.Bold = ture
selection.HomeKey Unit:=wdStory
'Selection.Find.ClearFormatting
With selection.Find
.Text = "Table [0-9]{1,}"
.Format = True
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
Do
.Execute
If Not .Found Then
Exit Do
ElseIf .Found Then
last_called = t_order(selection.Text, last_called)
End If
Loop
End With
'Selection.EndKey unit:=wdStory, Extend:=wdExtend
selection.HomeKey Unit:=wdStory, Extend:=wdMove
End Sub
Function t_order(AnyStr As String, last_call As Integer)
Dim RegEx
Set RegEx = CreateObject("vbscript.regexp")
With RegEx
.Global = True
.Pattern = "\d+"
End With
Set sql = RegEx.Execute(selection.Text)
For i = 0 To sql.count - 1
If Val(sql(i)) > last_call + 1 Then
'Selection.Comments.Add Range:=Selection.Range, Text:="incorrect citation order, table " & sql(i) & " detected after table " & last_call & ". "
selection.Comments.Add Range:=selection.Range, Text:="incorrect citation order, table " & sql(i) & " detected before table " & last_call + 1 & ". "
'Selection.Comments.Add Range:=Selection.Range, Text:="incorrect citation order. "
Else
If Val(sql(i)) > last_call Then
last_call = Val(sql(i))
End If
End If
If i + 1 <= sql.count - 1 Then 'make sure there is still one entry ahead
If Val(sql(i)) >= Val(sql(i + 1)) Then
selection.Comments.Add Range:=selection.Range, Text:="detected " & sql(i) & " before " & sql(i + 1) & ". This is wrong citation order."
End If
End If
Next i
t_order = last_call
Set RegEx = Nothing
Set dict = Nothing
End Function
检查大的数是不是在小的数前面先出现,然后报错,我已经可以做到了,但是如果大的数在小的数后面再次出现,那么不报错,我不知道怎么写。真的难死我了,求老师帮忙。
|
|