Deleting hard returns

L

LEU

I have the following that is part of my macro that goes into a table and get
some text. I thought the way I have it written it would delete the hard
return at the end. But when I load it into a bookmark there is a hard return
at the end still. Is there a way to delete this hard return so all I have in
the bookmarks is the text?

Getting the text:

With ActiveDocument.Tables(1)
strWord6 = .Cell(1, 3).Range.Text
strWord6 = Mid(strWord6, 1, Len(strWord6) - 2)

strWord8 = .Cell(3, 2).Range.Text
strWord8 = Mid(strWord8, 1, Len(strWord8) - 2)

strWord9 = .Cell(3, 5).Range.Text
strWord9 = Mid(strWord9, 1, Len(strWord9) - 2)
End With


Loading text into bookmark:

If ActiveDocument.Bookmarks.Exists("bkDate") Then
Set myrange = ActiveDocument.Bookmarks("bkDate").Range
myrange.Text = strWord6
ActiveDocument.Bookmarks.Add "bkDate", myrange
End If
If ActiveDocument.Bookmarks.Exists("bkDic") Then
Set myrange = ActiveDocument.Bookmarks("bkDic").Range
myrange.Text = strWord8
ActiveDocument.Bookmarks.Add "bkDic", myrange
End If
If ActiveDocument.Bookmarks.Exists("bkPCN") Then
Set myrange = ActiveDocument.Bookmarks("bkPCN").Range
myrange.Text = strWord9
ActiveDocument.Bookmarks.Add "bkPCN", myrange
End If

LEU
 
G

Greg

Using your code this would only happen if you had a superfilous paragraph
mark at the end of the cell text. The code you have strips the end of cell
marker (which has string length = 2). To strip the end of cell marker and a
paragraph mark you would have to strip the sting by 3. Another way is to use
the range like this:

Sub Test()
Dim StrWord6 As String
Dim myRange As Word.Range
With ActiveDocument.Tables(1)
Set myRange = .Cell(1, 3).Range
If myRange.Characters.Last.Previous = Chr(13) Then
myRange.MoveEnd wdCharacter, -2
Else
myRange.MoveEnd wdCharacter, -1
End If
StrWord6 = myRange.Text
End With
If ActiveDocument.Bookmarks.Exists("bkDate") Then
Set myRange = ActiveDocument.Bookmarks("bkDate").Range
myRange.Text = StrWord6
ActiveDocument.Bookmarks.Add "bkDate", myRange
End If
End Sub

BTW, when you post code for others it is helpful to declare all of your
variables.
 
L

LEU

Greg,

Thanks for the help and the info on my code. I'll make sure I do it from now
on.

LEU
 

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