Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.



Public Function BuildIndexTables()
' Procedure :   BuildIndexTables
' Description:  make sure we have the correct Index tables for the active document.
' By:           Chris Greaves Inc.
' Inputs:       None.
' Returns:      None.
' Assumes:      None.
' Side Effects: None
' Tested:       By the calls below.
' Form a list strI of all identifiers of {Index}.
' Form a list strX of all identifiers of {XE}.
' For entries in both strings, nothing to do.
' For entries in strI not in strX, remove the {Index}.
' For entries in strX not in strI, build the {Index}.
    Dim strI As String
    strI = strSortString(strFieldNames(ActiveDocument, wdFieldIndex))
    Dim strX As String
    strX = strSortString(strFieldNames(ActiveDocument, wdFieldIndexEntry))
    While strI <> "" And strX <> ""
        If Left$(strI, 1) = Left$(strX, 1) Then ' nothing to do
            strI = Right$(strI, Len(strI) - 1)
            strX = Right$(strX, Len(strX) - 1)
        Else
            If Left$(strX, 1) < Left$(strI, 1) Then ' need to build an {Index}
                Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
                    "INDEX \f" & Left$(strX, 1), PreserveFormatting:=False
                strX = Right$(strX, Len(strX) - 1)
           Else ' need to drop all {Index}
                Call RemoveNamedFields(ActiveDocument, wdFieldIndex, Left$(strI, 1))
                strI = Right$(strI, Len(strI) - 1)
            End If
        End If
    Wend
    While strX <> "" ' drop remaining {XE}
        Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
            "INDEX \f" & Left$(strX, 1), PreserveFormatting:=False
        strX = Right$(strX, Len(strX) - 1)
    Wend
    While strI <> "" ' drop remaining {Index}
        Call RemoveNamedFields(ActiveDocument, wdFieldIndex, Left$(strI, 1))
       strI = Right$(strI, Len(strI) - 1)
    Wend
'Sub TESTBuildIndexTables()
'Call BuildIndexTables
'End Sub
End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1

Visual Basic (VB and VBA)

Copyright 1999-2001 Christopher Greaves. All rights reserved.
Home Page and email to [email protected]
If in doubt, record a macro and inspect the entrails!

 

 

Please read the DISCLAIMER.

Here is an INDEX to all the procedures.

You will probably need one copy of my GLOBAL DECLARATIONS.

Public Function BuildIndexTables()
' Procedure :   BuildIndexTables
' Description:  make sure we have the correct Index tables for the active document.
' By:           Chris Greaves Inc.
' Inputs:       None.
' Returns:      None.
' Assumes:      None.
' Side Effects: None
' Tested:       By the calls below.
' Form a list strI of all identifiers of {Index}.
' Form a list strX of all identifiers of {XE}.
' For entries in both strings, nothing to do.
' For entries in strI not in strX, remove the {Index}.
' For entries in strX not in strI, build the {Index}.
    Dim strI As String
    strI = strSortString(strFieldNames(ActiveDocument, wdFieldIndex))
    Dim strX As String
    strX = strSortString(strFieldNames(ActiveDocument, wdFieldIndexEntry))
    While strI <> "" And strX <> ""
        If Left$(strI, 1) = Left$(strX, 1) Then ' nothing to do
            strI = Right$(strI, Len(strI) - 1)
            strX = Right$(strX, Len(strX) - 1)
        Else
            If Left$(strX, 1) < Left$(strI, 1) Then ' need to build an {Index}
                Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
                    "INDEX \f" & Left$(strX, 1), PreserveFormatting:=False
                strX = Right$(strX, Len(strX) - 1)
           Else ' need to drop all {Index}
                Call RemoveNamedFields(ActiveDocument, wdFieldIndex, Left$(strI, 1))
                strI = Right$(strI, Len(strI) - 1)
            End If
        End If
    Wend
    While strX <> "" ' drop remaining {XE}
        Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
            "INDEX \f" & Left$(strX, 1), PreserveFormatting:=False
        strX = Right$(strX, Len(strX) - 1)
    Wend
    While strI <> "" ' drop remaining {Index}
        Call RemoveNamedFields(ActiveDocument, wdFieldIndex, Left$(strI, 1))
       strI = Right$(strI, Len(strI) - 1)
    Wend
'Sub TESTBuildIndexTables()
'Call BuildIndexTables
'End Sub
End Function

We all knew nothing when we started …
Home Page and Contact Information
Send email to [email protected].
This page was last updated Thursday, November 15, 2001

 

 

Hosted by www.Geocities.ws

1