D
Dion Starfire
I'm trying to add some characters before and after a selected string of text
that may or may not contain a paragraph character (depending on what smart
selection features are in use). I want the inserted text to appear before any
paragraph mark, even if one is part of the selected text.
How can I make my script adjust the selection to exclude any paragraph
marks? My code so far works okay if a paragraph mark is included in the
selection, but otherwise it simply inserts both sets of characters before the
selected text.
Here's what I've got so far (I know it's messy, but I'm just dabbling here):
that may or may not contain a paragraph character (depending on what smart
selection features are in use). I want the inserted text to appear before any
paragraph mark, even if one is part of the selected text.
How can I make my script adjust the selection to exclude any paragraph
marks? My code so far works okay if a paragraph mark is included in the
selection, but otherwise it simply inserts both sets of characters before the
selected text.
Here's what I've got so far (I know it's messy, but I'm just dabbling here):
Code:
Dim SelLength As Single, PreLine As Single, PostLine As Single, Truend
As Integer
Dim LineHeader As String, LineEnder As String, strTemp As String
Dim TrimSpace As Integer
Truend = (Selection.Start + ((InStr(Selection.Text, Chr(13))) -
1)) 'locates Carriage return (ascii 13) in s
TrimSpace = (-1 * (Selection.End - Truend))
Selection.MoveEnd Unit:=wdCharacter, Count:=TrimSpace
SelLength = Selection.End - Selection.Start
PreLine = (80 - SelLength) / 2
PostLine = Int((80 - SelLength) / 2) ' Determines spaces needed
before and after to fill 80 columns
If Not (PreLine = Int(PreLine)) Then
Let PostLine = PostLine + 1
End If ' Adds additional character
at end for odd-numbered lengths
PreLine = Int(PreLine)
LineHeader = String(PreLine, "-")
LineEnder = String(PostLine, "-") ' Creates string of hyphens
equal to lengths determined earlier
Selection.InsertAfter (LineHeader)
Selection.InsertBefore (LineEnder)