kerrypnx
10/30/2018 - 6:19 AM

back matter order

revise 10-30

Sub backOrder()
Dim str, frontT As String
Dim myrange As Range
Dim existAuthorContributions, existConflicts, existFunding  As Boolean
existConflicts = False
existFunding = False
existAuthorContributions = False
str = "Supplementary Materials:,Author contributions:,Funding:,Acknowledgments:,Conflicts of Interest:,Abbreviations:,Appendix:,References:"
backM = Split(str, ",")
Set dict = CreateObject("Scripting.Dictionary")
Dim j, lastCall
j = 1: lastCall = 0
    For i = LBound(backM) To UBound(backM)
    
        dict.Add UCase(backM(i)), CStr(i)
    Next
Selection.HomeKey wdStory
With Selection.Find
    .ClearFormatting
    .Text = "[A-Z][a-z ]@\:"
    .Font.Size = 9
    .Font.Bold = True
    .MatchWildcards = True
    .Wrap = wdFindStop
    .Forward = True
    Do
    .Execute
    If Not .Found Then
        Exit Do
    Else
        Set myrange = ActiveDocument.Range(Selection.Paragraphs(1).Range.Start, Selection.Range.End)
        myrange.Select
'检测顺序
        If dict.Exists(UCase(myrange.Text)) = True Then
            If dict(UCase(myrange.Text)) > lastCall Then
                 lastCall = dict(UCase(myrange.Text))
            Else
                 myrange.comments.Add myrange, "'" + myrange.Text + "' " + "must be in front of " + "'" + frontT + "'"
            End If
        End If
        
    End If
        frontT = myrange.Text
            If LCase(frontT) = "author contributions:" Then
                existAuthorContributions = True
            End If
             If LCase(frontT) = "Conflicts of Interest:" Then
                existConflicts = True
            End If
            If LCase(frontT) = "Funding:" Then
                existFunding = True
            End If
        Selection.Collapse wdCollapseEnd
    Loop
    
            '检测有没有作者贡献
        If existAuthorContributions = False Then

            If Left(LCase(ActiveDocument.Paragraphs(1).Range.Text), 7) = "article" Then
                If InStr(ActiveDocument.Paragraphs(3).Range.Text, ", ") > 0 Or InStr(ActiveDocument.Paragraphs(3).Range.Text, " and ") > 0 Then
                
                    Call backMissing(2, "'Author Contributions'")
                    
                End If
            End If
        End If
        '检测有没有网上争议和funding
        If existConflicts = False Then
            Call backMissing(5, "'Author Contributions'")
        End If
        
        If existFunding = False Then
            Call backMissing(3, "'Author Contributions'")
        End If
            
End With
End Sub
Sub backMissing(startN As Integer, missT As String)
Dim backM, i, str

str = "Supplementary Materials:,Author contributions:,Funding:,Acknowledgments:,Conflicts of Interest:,Abbreviations:,Appendix:,References:"
backM = Split(str, ",")
    For i = startN To UBound(backM)
                        Selection.HomeKey wdStory
                        With Selection.Find
                        .ClearFormatting
                        .Text = backM(i)
                        .Font.Size = 9
                        .Font.Bold = True
                        .MatchWildcards = True
                        .Wrap = wdFindStop
                        .Forward = True
                            Do
                            .Execute
                                If Not .Found Then
                                    Exit Do
                                Else
                                    Selection.Range.comments.Add Selection.Range, missT + " part is missing, please add"
                                    Exit For
                                End If
                            Loop
                        End With
                    Next
End Sub