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 rngGetOutsideField(rngIn As Range, intType1 As Integer, Optional intType2) As Range
' Procedure:    rngGetOutsideField
' Description:  Locate all un-Included text.
' Copyright:    Chris Greaves Inc.
' Inputs:       DOCUMENT.
' Returns:      RANGE with special settings.
' Assumes:      Nothing
' Side Effects:
' Tested:       By the calls below.
' Method:
'   This early version is hard-coded to return All But {INCLUDETEXT} fields.
'   A later version will accept a list of optional Field types.
'
'   A STATIC variable is used to hold a limit of any existing {INCLUDETEXT} field.
'   Until this limit is reached we will return "failure"
'   Once this limit is passed, we will return "success"
'
'   Success will be a valid range.
'   Failure will be defined by setting the Range.End values to zero.
    If IsMissing(intType2) Then intType2 = intType1
    ' Skip character data until this range position is passed.
    Static lngNext As Long
    If (rngIn.Start = 0) Then ' We appear to have started a new document
        lngNext = -1
    Else
    End If
    If (lngNext = 0) Then
        lngNext = -1 ' First entry on this session, from any/all documents
    Else
    End If
    ' Set the default result
    Set rngGetOutsideField = rngIn
    rngIn.Select 'useful when debugging/single-stepping
    ' Can we establish a reason to avoid this text?
    If rngIn.Fields.Count > 0 Then ' we are about to step into it!
        ' Are any of the fields including text?
        Dim iFld As Integer
        For iFld = 1 To rngIn.Fields.Count
            If (rngIn.Fields(iFld).Type = intType1) Or (rngIn.Fields(iFld).Type = intType2) Then
                ' skipping fields: setting the end-marker.
                ' obtain the end-point of the first field as text
                If lngNext <= rngIn.Fields(iFld).Result.End Then
                    lngNext = rngIn.Fields(iFld).Result.End
                    ' but if the field itself is longer, well, use it!
                    If lngNext < rngIn.End Then
                        lngNext = rngIn.End
                    Else
                    End If
                Else
                End If
                Exit For
            Else
            End If
        Next iFld
    Else
    End If
    ' Do we have a continuing reason to avoid this text?
    If rngIn.Start < lngNext Then
        ' Bypassing fields because we already located a field.
        rngGetOutsideField.End = 0
    Else
        ' We are well-clear of any field-related stuff.
        Dim rng As Range
        Set rng = rngIn.Sentences(1)
    End If
'Sub TESTrngGetOutsideField()
'    Dim prg As Paragraph
'    For Each prg In ActiveDocument.Paragraphs
'        Dim rng As Range
'        Set rng = rngGetOutsideField(prg.Range, wdFieldIncludeText)
'        If rng.End = 0 Then ' we are  bypassing fields
'        Else
'            MsgBox rng.Text
'            MsgBox "1st sent " & rng.Sentences(1).Text
'        End If
'    Next prg
'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 rngGetOutsideField(rngIn As Range, intType1 As Integer, Optional intType2) As Range
' Procedure:    rngGetOutsideField
' Description:  Locate all un-Included text.
' Copyright:    Chris Greaves Inc.
' Inputs:       DOCUMENT.
' Returns:      RANGE with special settings.
' Assumes:      Nothing
' Side Effects:
' Tested:       By the calls below.
' Method:
'   This early version is hard-coded to return All But {INCLUDETEXT} fields.
'   A later version will accept a list of optional Field types.
'
'   A STATIC variable is used to hold a limit of any existing {INCLUDETEXT} field.
'   Until this limit is reached we will return "failure"
'   Once this limit is passed, we will return "success"
'
'   Success will be a valid range.
'   Failure will be defined by setting the Range.End values to zero.
    If IsMissing(intType2) Then intType2 = intType1
    ' Skip character data until this range position is passed.
    Static lngNext As Long
    If (rngIn.Start = 0) Then ' We appear to have started a new document
        lngNext = -1
    Else
    End If
    If (lngNext = 0) Then
        lngNext = -1 ' First entry on this session, from any/all documents
    Else
    End If
    ' Set the default result
    Set rngGetOutsideField = rngIn
    rngIn.Select 'useful when debugging/single-stepping
    ' Can we establish a reason to avoid this text?
    If rngIn.Fields.Count > 0 Then ' we are about to step into it!
        ' Are any of the fields including text?
        Dim iFld As Integer
        For iFld = 1 To rngIn.Fields.Count
            If (rngIn.Fields(iFld).Type = intType1) Or (rngIn.Fields(iFld).Type = intType2) Then
                ' skipping fields: setting the end-marker.
                ' obtain the end-point of the first field as text
                If lngNext <= rngIn.Fields(iFld).Result.End Then
                    lngNext = rngIn.Fields(iFld).Result.End
                    ' but if the field itself is longer, well, use it!
                    If lngNext < rngIn.End Then
                        lngNext = rngIn.End
                    Else
                    End If
                Else
                End If
                Exit For
            Else
            End If
        Next iFld
    Else
    End If
    ' Do we have a continuing reason to avoid this text?
    If rngIn.Start < lngNext Then
        ' Bypassing fields because we already located a field.
        rngGetOutsideField.End = 0
    Else
        ' We are well-clear of any field-related stuff.
        Dim rng As Range
        Set rng = rngIn.Sentences(1)
    End If
'Sub TESTrngGetOutsideField()
'    Dim prg As Paragraph
'    For Each prg In ActiveDocument.Paragraphs
'        Dim rng As Range
'        Set rng = rngGetOutsideField(prg.Range, wdFieldIncludeText)
'        If rng.End = 0 Then ' we are  bypassing fields
'        Else
'            MsgBox rng.Text
'            MsgBox "1st sent " & rng.Sentences(1).Text
'        End If
'    Next prg
'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