PDA

View Full Version : [SOLVED:] Code to capitalize 1st letter in each word in a table also adds LF



lkpederson
06-24-2014, 10:34 AM
Like the title says, my code is adding a hard return (line feed) at the end of each cell that it capitalizes the words. The hard returns are unwanted. I've tried moving the cursor back one character but that just moves the cursor back to next cell.

Ideas?

One item to note about the structure of the table: first row is all merged which is why I use .cell in lieu of column.



Sub CapitalizeSubmittalsInTable() Dim cRng As Range
Dim Chg As String
Dim n As Integer

n = ActiveDocument.Tables(2).Rows.Count
Selection.HomeKey Unit:=wdStory


For i = 4 To n
With ActiveDocument
Set cRng = .Range(Start:=.Tables(2).Cell(i, 3).Range.Start, _
End:=.Tables(2).Cell(i, 3).Range.End)
cRng.Select
cRng.Text = StrConv(cRng.Text, vbProperCase)
End With
Selection.MoveEnd Unit:=wdCharacter, Count:=1

Next i
End Sub

lkpederson
06-24-2014, 12:35 PM
Figured it out. Added cRng.End = cRng.End - 1 after "Set cRng = blah blah". Moves the cursor off the end of cell. See below.



Sub CapitalizeSubmittalsInTable()
Dim cRng As Range
Dim Chg As String
Dim n As Integer

n = ActiveDocument.Tables(2).Rows.Count
Selection.HomeKey Unit:=wdStory


For i = 4 To n
With ActiveDocument
Set cRng = .Range(Start:=.Tables(2).Cell(i, 3).Range.Start, _
End:=.Tables(2).Cell(i, 3).Range.End)
cRng.End = cRng.End - 1
cRng.Select
cRng.Text = StrConv(cRng.Text, vbProperCase)
End With
Next i
End Sub