|
Visual Basic (VB6 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! |
Visual Basic Library
This page was last updated on Saturday, November 24, 2001
Public Function blnIndexTableNames(doc As Document, strNameSearch As String) As Boolean ' Procedure : blnIndexTableNames ' Description: Return a string with the names of all {Index} table names in the document. ' By: Chris Greaves Inc. ' Inputs: DOCUMENT to be examined. ' Returns: None. ' Assumes: None. ' Side Effects: None ' Tested: By the calls below. blnIndexTableNames = False Dim fld As Field For Each fld In doc.Fields If fld.Type = wdFieldIndex Then Dim strFieldCodeText As String strFieldCodeText = UCase(fld.Code.Text) Dim iInstr As Integer iInstr = InStr(1, strFieldCodeText, "\F") If iInstr > 0 Then Dim strName As String strName = Trim(Right$(strFieldCodeText, Len(strFieldCodeText) - iInstr - 1)) strName = Trim(strOnly(strName, strcAlpha & " ")) If strNameSearch = strName Then blnIndexTableNames = True Exit For Else If InStr(1, strName, strNameSearch) > 0 Then blnIndexTableNames = True Exit For Else End If End If Else End If Else End If Next fld 'Sub TESTblnIndexTableNames() ' '' In your active document set up several {index} fields (Tables of index). '' Make sure that at least one is named with the \f switch to be "B" '' Make sure that at least one is named with the \f switch to be "Z" '' Make sure that at least one is named with the \f switch to be " " (space character) '' Make sure that at least one is named without the \f switch ' ''I made five indexes in my document: ''{Index \f " "}, {Index }, {Index \f "b"}, {Index \f "c"} and {Index \f "a"} '' Note the lower case letters I used for the switches, but upper-case in the tests! '' Then I ran these tests: ' 'If blnIndexTableNames(ActiveDocument, "B") Then ' MsgBox "Found such a table" ' OK, I did have an \f"b" switch 'Else ' MsgBox "Did not find such a table" 'End If ' 'If blnIndexTableNames(ActiveDocument, "Z") Then ' MsgBox "Found such a table" 'Else ' MsgBox "Did not find such a table" ' OK, I did not have an \f"z" switch 'End If ' 'If blnIndexTableNames(ActiveDocument, " ") Then ' MsgBox "Found such a table" ' OK, I made a \f" " switch (with a real space character!) 'Else ' MsgBox "Did not find such a table" 'End If ' 'If blnIndexTableNames(ActiveDocument, "") Then ' MsgBox "Found such a table" 'Else ' MsgBox "Did not find such a table" ' OK, a table with an \f " " switch is treated as an {Index} with no switch. '''' Selection.EndKey unit:=wdStory '''' Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _ '''' "INDEX ", PreserveFormatting:=False 'End If ' '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 Monday, November 19, 2001 |