kerrypnx
11/7/2018 - 4:21 AM

12. 检查作者贡献部分,作者名缩写是否跟前文部分作者名对应(Name abbreviations are not consistent with the names in front part)

revise 11-7

Sub detectAuthorNameAbbr()
  Dim authorName As String

  authorName = getAuthourAbbr(ActiveDocument.Paragraphs(3).Range.Text)
Selection.HomeKey wdStory
    With Selection.Find
        .ClearFormatting
        .Text = "Author Contributions:"
        .Font.Bold = -1
        .MatchWildcards = False
        .Execute
        If .Found Then
        Selection.Paragraphs(1).Range.Select
            Call getErrorAuthourIndex(Selection.Text, authorName)
                
        End If
    End With
End Sub
Function getAuthourAbbr(str As String) As String
    Dim reg As New RegExp
    Dim matches
    With reg
        .Global = -1
        .Pattern = "[-]?[a-zA-Z]+"
        Set matches = .Execute(str)
    End With
    For Each m In matches
      If InStr(m, "-") > 0 Then
      getAuthourAbbr = getAuthourAbbr + Left(m, 2) + "."
      Else
        getAuthourAbbr = getAuthourAbbr + Left(m, 1) + "."
                       
        End If
    Next
End Function
Sub getErrorAuthourIndex(str As String, str1 As String)
  Dim Index, myL As Integer
  Dim myrange As Range
    Dim reg As New RegExp
    Dim matches
    Dim getErrorAuthourIndex As String
    With reg
        .Global = -1
        .Pattern = "([-]?[A-Z]\.)+ "
        Set matches = .Execute(str)
    End With
    If matches.count = 0 Then
        Selection.Range.HighlightColorIndex = wdRed
        Selection.Range.comments.Add Selection.Range, "Name abbreviations are not consistent with the names in front part"
        Exit Sub
    End If
    
    For Each m In matches
    
      If InStr(str1, Trim(m)) > 0 Then
       
    Else
        
        getErrorAuthourIndex = CStr(m.firstindex) + ";" + CStr(Len(m))
         arr1 = Split(getErrorAuthourIndex, ";")
                Index = CInt(arr1(0))
                myL = CInt(arr1(1))
            If Index > 0 Then
                Set myrange = ActiveDocument.Range(Selection.Range.Start + Index, Selection.Start + Index + myL)
                myrange.HighlightColorIndex = wdRed
                myrange.comments.Add myrange, "Name abbreviations are not consistent with the names in front part"
            End If
      End If
    Next
End Sub
Sub tttpp()
    MsgBox InStr("L.Z.P.S.R.S.L.S.", Trim("P.A.S."))
End Sub