PDA

View Full Version : Solved: Format issues with combined documents (tables)



espencer
08-24-2005, 12:06 PM
Hello,
I'm hoping someone can steer me in the right direction for this issue. I have a macro that combines other word documents into another word document from the same path.
When I run this macro it inserts note02 into note01. My issue is the in note02 is a table and after the insert the format of the table is larger than it should be. I've tried a lot of vba command and nothing seems to work.
I was wondering and hoping that someone has done this before and can help or steer me to some information on this issue.

Thanks in advance.

Files: Note01.doc, Note02.doc
instructions;
1. Copy note01 & note02 in the same directory
2. Open note01.doc
3. Run Macro

Macro:

Sub DefaultfootnoteCombo()

Selection.EndKey Unit:=wdStory
Selection.InsertBreak Type:=wdSectionBreakNextPage
With Selection.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(0.56)
.BottomMargin = InchesToPoints(1)
.LeftMargin = InchesToPoints(1)
.RightMargin = InchesToPoints(1)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(0.5)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionContinuous
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = True
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
With Selection.Sections(1)
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
With .Borders
.DistanceFrom = wdBorderDistanceFromPageEdge
.AlwaysInFront = True
.SurroundHeader = True
.SurroundFooter = True
.JoinBorders = False
.DistanceFromTop = 24
.DistanceFromLeft = 24
.DistanceFromBottom = 24
.DistanceFromRight = 24
.Shadow = False
.EnableFirstPageInSection = True
.EnableOtherPagesInSection = True
.ApplyPageBordersToAllSections
End With
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth300pt
.DefaultBorderColor = wdColorGray50
End With

Selection.InsertFile FileName:=ActiveDocument.Path & "" & "note02.doc", Range:="" _
, ConfirmConversions:=False, Link:=True, Attachment:=False

End Sub

geekgirlau
08-24-2005, 03:52 PM
I've run the macro and the table looks fine. I did see a missing "\" in the following:


Selection.InsertFile FileName:=ActiveDocument.Path & "\" & "note02.doc", Range:="" _
, ConfirmConversions:=False, Link:=True, Attachment:=False


I do have concerns about the structure of the document - why so many section breaks?

fumei
08-25-2005, 12:16 AM
1. I too find the multitude of section breaks unusual. Could you explain why this is needed???

2. I looked for the macro code and it is in neither of documents i downloaded. Have I missed it? or do I have to recrerate the code to test.

3. If I may, is this basically trying to insert Note02.doc at the of Note01.doc, but maintain the format of the table in Note02.doc?

Please confirm.

espencer
08-25-2005, 03:23 AM
In reply to your question, yes. The section breaks are area where the user can enter text if needed. I have other document to add to this but I lose the format of the at the beginning on the area that has note 2 on the document. Should I add code for the sections?

geekgirlau
08-25-2005, 10:35 PM
I think you've misunderstood the purpose of a section break. You really only need them if you are changing page formatting options for part of the document (for example, different headers/footers, part of your document in columns, landscape page in the middle of portrait pages etc.).

If your purpose is just to leave a blank line, then press Enter to leave a paragraph mark at that spot. You may find that the only section break you need is at the end of the document where you are going to insert Note 2, but this is required only if the inserted document has different margins etc.

espencer
08-26-2005, 03:19 AM
This project was handed over to me and I will be sure to make that change. Every time I try to run this macro the table in note02 expands. Try to run the macro with just the table in each note. Actually theirs more notes to add to this but I'm just trying to get it started. all of the notes are formatted differently and most of them have different margins and all of the have tables. Thanks for your advice and I will use it wisely.

fumei
08-29-2005, 10:15 AM
Hi, geekgirlau
1.

If your purpose is just to leave a blank line, then press Enter to leave a paragraph mark at that spot.

WHOA!!!!! Bad advice. I strongly belive people should be encouraged to use styles in Wiord. Word is designed for styles, and IMHO, an "extra" paragraph marks is never to be encouraged. That space between paragraphs should always be done with styles.

2. Section are indeed used for format changes (marhins etc etc yadda yadda), but section breaks used to lock editing for protected sections is a very legitimate use of section breaks - regardless of whether formfields are used or not. Locking sections fo forms (even without formfields) locks that section for edits. This is quite reasonable. Although certainly the NUMBER of section breaks in the sample doc attached indicates - hmmmmm, not particularly good design.

espencer - the same docs have poor design with the section breaks. I am positive that half of these can be removed, and SHOULD BE.

Further, your code initially make a Section break Next page. OK, but then down in your code you have:

.SectionStart = wdSectionContinuous

which CHANGES the inserted section break (next page) back into a Continuous Section break.

Therefore....all your margins changes etc etc. have now be made null and void. Those do NOT apply to continuous sections. You made all those lovely changes....then negated them.

geekgirlau
08-30-2005, 01:38 AM
WHOA!!!!! Bad advice. I strongly belive people should be encouraged to use styles in Wiord. Word is designed for styles, and IMHO, an "extra" paragraph marks is never to be encouraged. That space between paragraphs should always be done with styles. Actually Fumei, I'm not advocating an "extra" paragraph mark - I'm advising that a blank paragraph mark be left for paragraphs that are to be inserted by the user, not to create extra space in the document. By all means styles would control the space between paragraphs, but this is not what we're talking about here.


2. Section are indeed used for format changes (marhins etc etc yadda yadda), but section breaks used to lock editing for protected sections is a very legitimate use of section breaks - regardless of whether formfields are used or not. Locking sections fo forms (even without formfields) locks that section for edits. This is quite reasonable. Although certainly the NUMBER of section breaks in the sample doc attached indicates - hmmmmm, not particularly good design.

Again, the advice given is specifically in terms of the document in question - WAY too many section breaks IMHO.

espencer
08-30-2005, 03:14 AM
I've tried to run this macro on the two notes without all of the section breaks and still getting the same results. The table on the second page is larger than original. Can you try this and let me know what's wrong with the code.

fumei
08-30-2005, 11:57 AM
Not sure what the difference is between an extra paragraph mark, and a blank paragraph. They seem the same to me.

Definitely way too many section breaks.

It is not that the table is bigger. It is a style issue.

Note01.doc has the text in the table using Body Text 2 + Arial blah blah blah. It is based on Body Text 2

Note02.doc has the text in the table using Body Text Indent + Arial blah blah blah. It is based on Body Text Indent.

If you turn Show/Hide ON, you can see the end of cell marker is moved over. Which forces the text to drop down a line, which forces the table to be "bigger".

1. Use consistent styles
2. Use explicit names for styles.

The use of styles is VERY messed up in this document. For example, I recreated the documents using explicit styles for the contents of the tables - TableHeadingItems, TableItems, TableYears, TableAmounts....and that pretty much took care of that.

The table with "Notes" I made a NotesTable style.

When both documents use the same styles, the file Note02.doc inserts perfectly.

I suggest you also use Show/Hide on. If you do, you will also notice that sometime you use the spacebar to indent items in the table, and sometimes you use Tab. You should try to be consistent, and even better....use styles.

The easy fix for your code, if you do not want to bother in making proper use of styles is:

Sub GetOtherNote()
With Selection
.EndKey unit:=wdStory
.InsertBreak Type:=wdSectionBreakNextPage
.InsertFile FileName:=ActiveDocument.Path & _
"\" & "note02.doc"
' go back to the Notes table
.GoTo What:=wdGoToTable, _
Which:=wdGoToPrevious, Count:=2, Name:=""
' select first cell and reset style
' and MANUAL formatting
.Tables(1).Cell(1, 1).Select
.Style = ActiveDocument.Styles("Body Text 2")
' none of the following would be needed
' if properly used styles
With .Font
.Bold = True
.Size = 14
.NameAscii = "Arial"
.Underline = 0
End With
.EndKey unit:=wdStory
End With
End Sub

espencer
08-31-2005, 09:08 AM
Thanks for helping and being patience with me. This works fine for me.