PDA

View Full Version : Paragraph Styles in Table Cells



ckb
03-06-2012, 08:40 PM
I have been scratching my head at this code for a few days now with great frustration.

The background: client wants document formatted with a certain look. Essentially, anything I have as a "Heading 1" or "Heading 2" has to end up on the left side of the page, and anything else has to end up on the right side of the page (Heading 3, Heading 4, etc, as well as a few hidden text styles. The first line of text on the right has to be vertically aligned with the preceding heading 2.

The first thing I tried was to use text columns, and through a combination of section breaks and column breaks. While I can get this to work, as soon as there is a page break, the system falls apart.

The 2nd thing I tried was to use a table with two columns. If the text is Heading 1 or Heading 2, add a row and set the left cell's text as the Heading 1 or Heading 2, respectively, and if anything else, add the text to the (now existing) empty right cell, and apply paragraph styles to each paragraph in the cell. This seems to be falling apart, and I can't figure out why.

A short code fragment:

For i = i to ActiveDocuments.Paragraphs.Count
If ...
...
Else 'Any Paragraph Style Not "Heading 1" or "Heading 2"
With myTable
.Cell(.Rows.Count, 2).Range.Paragraphs.Last.Range.Text = .Cell(.Rows.Count, 2).Range.Paragraphs.Last.Text & Left(ActiveDocument.Paragraphs(i).Range.Text, Len(ActiveDocument.Paragraphs(i).Range.Text) - 1)
.Cell(.Rows.Count, 2).Range.Paragraphs.Last.Style = ActiveDocument.Paragraphs(i).Style
End With
End If
Next

The result is that only the last paragraph in the cell has the correct style, and the rest seem to lose the style they were supposed to have.

I cannot do an individual cell for each paragraph by creating a new row due to the aformentioned hidden text styles, since when they turn off, the result would be a blank line adjacent to the Heading 1 or Heading 2.

Any help is appreciated.

fumei
03-06-2012, 10:02 PM
Use your own styles. No table.

Paul_Hossler
03-07-2012, 01:13 PM
Essentially, anything I have as a "Heading 1" or "Heading 2" has to end up on the left side of the page, and anything else has to end up on the right side of the page (Heading 3, Heading 4, etc, as well as a few hidden text styles. The first line of text on the right has to be vertically aligned with the preceding heading 2.


I'm not sure what you mean by 'right side'


Example: assume

8.5 x 11 inch, 1 in margins, so 6.5 inches per line


1. This

0" -- HEADING 1 --- 1"
0" -- HEADING 2 --------------- 2"
............................................2" --- HEADING 3 ---------- 4"


and later

0" -- HEADING 1 --------------- 3"
0" -- HEADING 2 --------------- ------------ 3"
............................................................3" --- HEADING 3 ---------- 6"



2. or just right aligned?

0" -- HEADING 1 --------------- 3"
0" -- HEADING 2 --------------- ------------ 3"
........................................................................... ......5" --- HEADING 3 ---------- 6.5"


If it's #1, I don't see how using styles would allow different instances of HEading3 to start with different indents

if it's #2, then styles are the way to go


Paul

PS. Yes, it's an ugly picture, but it's the best i could do

Do you have a sample of the desired results?

Frosty
03-07-2012, 01:52 PM
Have you looked at defining Headings 1 & 2 as being styles with Frames, and then the rest of your styles have a significant left indent (say, 3")... so basically you have "floating" headings, while the main text of your document lives mostly on the right side of the page. You have to tweak the location of the frame within the styles in order to line up, but it's do-able.

I've attached a sample document with styles Heading 1-3 and Normal styled in the way I mean.

I think Paul is right-- if you can give a sample document (you'll need 5 posts to be able to upload an attachment, so simply reply to this thread a few times until you can attach), it will be easier to help.

ckb
03-08-2012, 08:03 PM
Frosty, I will have a look at what you proposed.

ckb
03-08-2012, 08:05 PM
Arguably, if I can use styles and program them in just the way I want to get this appearance it will make my life infinitely easier. Essentially I have several dozen word docs that I am applying the same .dot template to, and then my macro needs be only "apply this .dot template" which is very very simple.

ckb
03-08-2012, 08:07 PM
I had a quick look at Frosty's suggestion, and it didn't appear correct in LibreOffice (I don't have word installed on my home computer...)

Hopefully I can post the link in my next post.

ckb
03-08-2012, 08:09 PM
Nope... need one more.

ckb
03-08-2012, 08:10 PM
This is an example I picked at random from the client that shows the general appearance. As implemented by them it's downright horrible and frankly would be a fate worse than death to work with:
ftp://ftp.tpsgc.gc.ca/rps/Specifications/Master%20Specifications/RTF%20Master%20Specs/PWGSC%20Amended%20NMSS2011%20RTF/06%20Amended%20RTF/ES061400.rtf.