Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2006

Tip: Looking for answers? Try searching our database.

paragraph format on selected cells in a table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tbaam - 12 Apr 2006 15:03 GMT
What am I doing wrong?

I looked at old posts and wrote the following piece of  code. It searches a
table for a section of rows and keeps them together. I then want then to stay
together and if necessary go to the next page.

I can the see the lines highlight as expected but the paragraph format does
not seem to be doing what it is suppose to.

Thanks
Sub Macro1()
Dim i
Dim End_row, Start_row, New_row As Integer
Dim num
   'num = Selection.Columns(1).Cells.Count
   Row = 3
   For i = 4 To 400
       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
           End_row = i
           With ActiveDocument.Tables(2)
               pos = .Cell(Row, 1).Range.Start
               posEnd = .Cell(End_row, 5).Range.End
               Set myrange = ActiveDocument.Range(Start:=pos, End:=posEnd)
               myrange.Select
               'Selection.myrange
               With Selection.ParagraphFormat
                   .WidowControl = True
                   .KeepWithNext = True
                   .KeepTogether = True
                   .PageBreakBefore = False
               End With
           End With
         Row = i
       End If
   Next i
End Sub
Jezebel - 12 Apr 2006 23:10 GMT
> 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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.