> What am I doing wrong?
1. You haven't defined your objective. It's not obvious from the code
(which, on your own admission, doesn't work anyway).
2. You're trying to apply paragraph formatting to indeterminate ranges
across mulitple table cells. This generally doesn't work. Format the
paragraphs within this range.
3. You can't have read the documentation on variable declarations. Otherwise
you wouldn't have ended up with one obsolete data type and four slow and
inappropriate ones.
4. You're using the Selection object where a Range object would be more
appropriate.
> I looked at old posts and wrote the following piece of code. It searches
> a
[quoted text clipped - 36 lines]
> Next i
> End Sub
tbaam - 14 Apr 2006 16:02 GMT
My objective: I have a table that scans multiple pages in Word. At the end
of each page are a series of rows that I am trying to keep together. Once I
determine this set of rows I want to use paragraph formatting and keep with
next.
I went back and read and understand what I did wrong. As the macro runs I
can see the rows being selected. But, the paragraph format does not work. If
I replace the paragraph format, with change font size, I can see that work.
So it has to do with the paragraph format command.
Sub Macro1()
Dim i
StartRow = 3
For i = 4 To 100
Value = Left(ActiveDocument.Tables(2).Cell(Row:=i,
Column:=1).Range.Text, Len(ActiveDocument.Tables(2).Cell(Row:=i,
Column:=1).Range.Text) - 2)
If Value < 100 Then
EndRow = i - 1
MsgBox EndRow
Set myrange = ActiveDocument.Range( _
Start:=ActiveDocument.Tables(2).Cell(StartRow,
1).Range.Start, _
End:=ActiveDocument.Tables(2).Cell(EndRow, 5).Range.End)
myrange.Select
With myrange.ParagraphFormat.KeepWithNext = True
End With
End If
StartRow = EndRow + 1
Next i
End Sub
> > What am I doing wrong?
>
[quoted text clipped - 52 lines]
> > Next i
> > End Sub