Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-04-2014, 04:07 AM
RoMu RoMu is offline Add Break at end of doc, control display of non-printable characters Windows 7 64bit Add Break at end of doc, control display of non-printable characters Office 2010 32bit
Novice
Add Break at end of doc, control display of non-printable characters
 
Join Date: Mar 2014
Posts: 6
RoMu is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 03-04-2014, 04:10 PM
macropod's Avatar
macropod macropod is offline Add Break at end of doc, control display of non-printable characters Windows 7 32bit Add Break at end of doc, control display of non-printable characters Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
With appWord.ActiveDocument
  .Sections.Add Start:=wdSectionNewPage
  .Tables(1).Range.Copy
  .Characters.Last.Paste
End With
Note that nothing ever gets selected.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 03-05-2014, 01:41 AM
RoMu RoMu is offline Add Break at end of doc, control display of non-printable characters Windows 7 64bit Add Break at end of doc, control display of non-printable characters Office 2010 32bit
Novice
Add Break at end of doc, control display of non-printable characters
 
Join Date: Mar 2014
Posts: 6
RoMu is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 03-05-2014, 02:10 PM
macropod's Avatar
macropod macropod is offline Add Break at end of doc, control display of non-printable characters Windows 7 32bit Add Break at end of doc, control display of non-printable characters Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #5  
Old 03-06-2014, 02:33 AM
RoMu RoMu is offline Add Break at end of doc, control display of non-printable characters Windows 7 64bit Add Break at end of doc, control display of non-printable characters Office 2010 32bit
Novice
Add Break at end of doc, control display of non-printable characters
 
Join Date: Mar 2014
Posts: 6
RoMu is on a distinguished road
Default

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
Attached Files
File Type: zip TESTDocs.zip (12.8 KB, 10 views)
Reply With Quote
  #6  
Old 03-06-2014, 02:50 AM
macropod's Avatar
macropod macropod is offline Add Break at end of doc, control display of non-printable characters Windows 7 32bit Add Break at end of doc, control display of non-printable characters Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #7  
Old 03-06-2014, 04:24 AM
RoMu RoMu is offline Add Break at end of doc, control display of non-printable characters Windows 7 64bit Add Break at end of doc, control display of non-printable characters Office 2010 32bit
Novice
Add Break at end of doc, control display of non-printable characters
 
Join Date: Mar 2014
Posts: 6
RoMu is on a distinguished road
Default

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
Reply With Quote
Reply

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
Add Break at end of doc, control display of non-printable characters 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

Other Forums: Access Forums

All times are GMT -7. The time now is 08:50 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft