removing paragraph mark from selection

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):
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)
 
G

Greg Maxey

You only want to move the Selecton.En "IF" there is a Chr(13) in the
selection.

If InStr(Selection.Text, Chr(13)) > 0 Then
Selection.MoveEnd Unit:=wdCharacter, Count:=-lngTrim
End If




Sub Test()
Dim lngEnd As Long
Dim SelLength As Single, PreLine As Single, PostLine As Single
Dim LineHeader As String, LineEnder As String, strTemp As String
Dim lngTrim As Long
lngEnd = (Selection.Start + ((InStr(Selection.Text, Chr(13))) -
1)) 'locates Carriage return (ascii 13)
lngTrim = Selection.End - lngEnd
If InStr(Selection.Text, Chr(13)) > 0 Then
Selection.MoveEnd Unit:=wdCharacter, Count:=-lngTrim
End If
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
PostLine = PostLine + 1
End If ' Adds additional
characterat end for odd-numbered lengths
PreLine = Int(PreLine)
LineHeader = String(PreLine, "-")
LineEnder = String(PostLine, "-") ' Creates string of
hyphensequal to lengths determined earlier
Selection.InsertAfter (LineHeader)
Selection.InsertBefore (LineEnder)
End Sub






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 beforeany
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 beforethe
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 spacesneeded
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)
 
D

Dion Starfire

Thanks for the info.

I'd been assuming that InStr would return a 0 if it couldn't find the value,
so the selection would be shortened by 0. Turns out I was wrong, which is
really no big surprise. *L*


Greg Maxey said:
You only want to move the Selecton.En "IF" there is a Chr(13) in the
selection.

If InStr(Selection.Text, Chr(13)) > 0 Then
Selection.MoveEnd Unit:=wdCharacter, Count:=-lngTrim
End If




Sub Test()
Dim lngEnd As Long
Dim SelLength As Single, PreLine As Single, PostLine As Single
Dim LineHeader As String, LineEnder As String, strTemp As String
Dim lngTrim As Long
lngEnd = (Selection.Start + ((InStr(Selection.Text, Chr(13))) -
1)) 'locates Carriage return (ascii 13)
lngTrim = Selection.End - lngEnd
If InStr(Selection.Text, Chr(13)) > 0 Then
Selection.MoveEnd Unit:=wdCharacter, Count:=-lngTrim
End If
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
PostLine = PostLine + 1
End If ' Adds additional
characterat end for odd-numbered lengths
PreLine = Int(PreLine)
LineHeader = String(PreLine, "-")
LineEnder = String(PostLine, "-") ' Creates string of
hyphensequal to lengths determined earlier
Selection.InsertAfter (LineHeader)
Selection.InsertBefore (LineEnder)
End Sub






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):
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top