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 rngLines(ByVal rng As Range, intN As Integer) As Range
' Procedure :   rngLines
' Description:  return a range of lines from a range of text.
' By:               Chris Greaves Inc.
' Inputs:          A range, a desired line count.
' Returns:        RANGE
' Assumes:      Nothing
' Side Effects: None.
' Tested:       By the calls shown below.
    ' First determine the limit of lines that we could expect to find
    Dim lngLines As Long
    lngLines = lngCountLines(rng)
    If lngLines > intN Then ' we have more than enough.
        lngLines = intN
    Else
    End If
    ' Now attempt to define the required range
    Dim lngStart As Long
    rng.Select
    Selection.HomeKey
    lngStart = Selection.Start ' we start at the start
       Selection.MoveDown Unit:=wdLine, Count:=lngLines
    Dim lngEnd As Long
    lngEnd = Selection.End
    If lngStart = lngEnd Then ' there was only one line
        Selection.EndKey Extend:=wdExtend
        Set rngLines = Selection.Range
    Else
        Set rngLines = Selection.Range
        rngLines.Start = lngStart
        rngLines.End = lngEnd
    End If
'Sub TESTrngLines()
'MsgBox rngLines(Selection.Range, 4)
'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 rngLines(ByVal rng As Range, intN As Integer) As Range
' Procedure :   rngLines
' Description:  return a range of lines from a range of text.
' By:               Chris Greaves Inc.
' Inputs:          A range, a desired line count.
' Returns:        RANGE
' Assumes:      Nothing
' Side Effects: None.
' Tested:       By the calls shown below.
    ' First determine the limit of lines that we could expect to find
    Dim lngLines As Long
    lngLines = lngCountLines(rng)
    If lngLines > intN Then ' we have more than enough.
        lngLines = intN
    Else
    End If
    ' Now attempt to define the required range
    Dim lngStart As Long
    rng.Select
    Selection.HomeKey
    lngStart = Selection.Start ' we start at the start
       Selection.MoveDown Unit:=wdLine, Count:=lngLines
    Dim lngEnd As Long
    lngEnd = Selection.End
    If lngStart = lngEnd Then ' there was only one line
        Selection.EndKey Extend:=wdExtend
        Set rngLines = Selection.Range
    Else
        Set rngLines = Selection.Range
        rngLines.Start = lngStart
        rngLines.End = lngEnd
    End If
'Sub TESTrngLines()
'MsgBox rngLines(Selection.Range, 4)
'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