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 rngGetNextField(strType As String, Optional strName As String = "") As Range
' Procedure :   rngGetNextField
' Description:  get the range object for the next field.
' By:           Chris Greaves Inc.
' Inputs:       String field typoe (e.g. "SEQ"), optional field identifier (e.g. "MyNumb")
' Returns:      Range
' Assumes:      Nothing
' Side Effects: None.
' Tested:       By the calls shown below.
    Set rngGetNextField = Selection.Range ' default result is our current position.
    ' Try for the first field of any sort
    Selection.GoTo what:=wdGoToField, Which:=wdGoToNext, Count:=1, Name:=strType
    ' Select the found field
    Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    While Selection.Range.Fields.Count > 0 ' then we do indeed have a field
        Set rngGetNextField = Selection.Range ' which is our result unles sproved otherwise
        Dim strThisType As String
        strThisType = strSplitStringAt(Selection.Range.Fields(1).Code.Text, " ", False)
        If Left$(strThisType, Len(strType)) = strType Then ' it is the correct TYPE of field (e.g. "SEQ")
'            If IsMissing(strName) Then ' we are done
'                Exit Function
'            Else
                Dim strThisName As String
                strThisName = strSplitStringAt(strThisType, " ", False)
                strThisName = strSplitStringAt(strThisName, " ", True)
                If UCase$(Left$(strThisName, Len(strName))) = UCase$(strName) Then
                    Exit Function
                Else
                End If
'            End If
        End If
        Selection.MoveRight Unit:=wdCharacter, Count:=1 ' skip past this field
        Selection.GoTo what:=wdGoToField, Which:=wdGoToNext, Count:=1, Name:=strType ' and find the next
        Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    Wend
'Sub TESTrngGetNextField()
'    Selection.HomeKey Unit:=wdStory
'    MsgBox rngGetNextField("SEQ", "BBPage").Start
'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 rngGetNextField(strType As String, Optional strName As String = "") As Range
' Procedure :   rngGetNextField
' Description:  get the range object for the next field.
' By:           Chris Greaves Inc.
' Inputs:       String field typoe (e.g. "SEQ"), optional field identifier (e.g. "MyNumb")
' Returns:      Range
' Assumes:      Nothing
' Side Effects: None.
' Tested:       By the calls shown below.
    Set rngGetNextField = Selection.Range ' default result is our current position.
    ' Try for the first field of any sort
    Selection.GoTo what:=wdGoToField, Which:=wdGoToNext, Count:=1, Name:=strType
    ' Select the found field
    Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    While Selection.Range.Fields.Count > 0 ' then we do indeed have a field
        Set rngGetNextField = Selection.Range ' which is our result unles sproved otherwise
        Dim strThisType As String
        strThisType = strSplitStringAt(Selection.Range.Fields(1).Code.Text, " ", False)
        If Left$(strThisType, Len(strType)) = strType Then ' it is the correct TYPE of field (e.g. "SEQ")
'            If IsMissing(strName) Then ' we are done
'                Exit Function
'            Else
                Dim strThisName As String
                strThisName = strSplitStringAt(strThisType, " ", False)
                strThisName = strSplitStringAt(strThisName, " ", True)
                If UCase$(Left$(strThisName, Len(strName))) = UCase$(strName) Then
                    Exit Function
                Else
                End If
'            End If
        End If
        Selection.MoveRight Unit:=wdCharacter, Count:=1 ' skip past this field
        Selection.GoTo what:=wdGoToField, Which:=wdGoToNext, Count:=1, Name:=strType ' and find the next
        Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    Wend
'Sub TESTrngGetNextField()
'    Selection.HomeKey Unit:=wdStory
'    MsgBox rngGetNextField("SEQ", "BBPage").Start
'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