#1
|
|||
|
|||
Add Break at end of doc, control display of non-printable characters
Hello all,
using Office 2010, I have written a macro in VBA, which copies the table on first page (table is smaller than the page itself) to the second page. The first table is being selected and copied by using the following commands (the macro is in Excel, controlling the Word application). With appWord.ActiveDocument.Tables(1) .Select End With appWord.Selection.Copy appWord.Selection.EndKey Unit:=wdStory appWord.Selection.InsertBreak Type:=wdSectionBreakNextPage appWord.Selection.Paste This works fine as long as the display of non-printing characters in Word is switched on. If this option is switched off, the break to the next page does not happen. In that case the pasted table splits between page one and two. 1. Is there a better way to make sure that the insertion of the break succeeds ? 2. Is there a way to switch the display of non-printing characters in Word on/off through VBA ? Thanks Rolf |
#2
|
||||
|
||||
Try:
Code:
With appWord.ActiveDocument .Sections.Add Start:=wdSectionNewPage .Tables(1).Range.Copy .Characters.Last.Paste End With
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Hi Paul,
thanks for your suggestion. Have tried and found that this approach as well depends on the option to have visibility of non-printing characters switched on. In parallel I was looking for a solution to prevent word from breaking to a new page within a table and applied the settings explained in http://ragrawal.wordpress.com/2008/0...s-in-one-page/ (approach is quite similar for WORD 2010). Combining your suggestion with the explained style settings leads to success (as far as I was able to test). So thanks to you and the author of the style settings, Ritesh Agrawal, for solving my problem. Kind regards Rolf |
#4
|
||||
|
||||
In my testing, the visibility settings have no effect on how the code works. That suggests there's either some corruption in your document or a fault in your Word installation.
Corrupt documents can often be 'repaired' by inserting a new, empty, paragraph at the very end, copying everything except that new paragraph to a new document based on the same template, closing the old document and saving the new one over it. Similarly, corrupt tables can often be 'repaired' by converting the tables to text and back again or by saving the document in RTF format, closing the document then re-opening it and re-saving in the doc(x) format. A faulty Office installation can usually be repaired via Programs & Features > Microsoft Office > Change in the Windows Control Panel.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Hi Paul,
thanks for your suggestions about corrupted document/table/word installation. Have successfully repaired office (with no indication to a repaired problem), have converted the table to text and back again, have gone throth the .rtf and back to .dot conversion, but none of them has resolved the problem (different handling between non-printing chars. Setting them on -> OK, one complete table per page setting them off -> Not OK, table splits between page 1 and 2). The only way for me to reliably solve the problem is setting the style options for paragraph in the table(1) to “Keep With Next” and “Keep Lines Together”. In case you would like to test the table I'm using, I have attached 2 docs in a .zip package. One that is not OK and one that containes the settings described above, which works ok. Thanks and kind regards Rolf |
#6
|
||||
|
||||
The issue with your document is that you have formatted the table with 'around' text wrapping. It would have been helpful if you'd mentioned that. Try:
Code:
Dim bShow As Boolean With appWord.ActiveDocument bShow = .ActiveWindow.ActivePane.View.ShowAll .ActiveWindow.ActivePane.View.ShowAll = True .Sections.Add Start:=wdSectionNewPage .Tables(1).Range.Copy .Characters.Last.Paste .ActiveWindow.ActivePane.View.ShowAll = bShow End With
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Hi Paul,
thanks for the new code, works great. Sorry I wasn't aware of that formatting issue 'around' text wrapping. Still need to increase my knowledge about word formatting. Many thanks for your help Rolf |
Tags |
non-printing characters, page break, vba |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
how to make building block content control determine bb to display elsewhere | jamles12 | Word VBA | 5 | 11-16-2013 11:38 AM |
display number of characters in a word section | shootingluc | Word | 3 | 03-29-2012 03:25 PM |
How to display those characters in word properly? | Srivas | Word | 2 | 03-28-2011 12:02 AM |
paragaph hard break, soft break and ...strange break | czomberzdaniela | Word | 2 | 12-03-2010 06:58 PM |
Junk characters (box-like characters) in Word file | Sashikala | Word | 1 | 04-20-2010 02:03 PM |