Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-28-2012, 03:30 AM
ramsgarla ramsgarla is offline Selection of all Text for a specific page in word is spanning selection across pages Windows 7 64bit Selection of all Text for a specific page in word is spanning selection across pages Office 2010 64bit
Novice
Selection of all Text for a specific page in word is spanning selection across pages
 
Join Date: Sep 2012
Posts: 21
ramsgarla is on a distinguished road
Default Selection of all Text for a specific page in word is spanning selection across pages

I am trying to iterate through each and every page in RTF document
and select all the text page by page and apply certain business rules.

Below mentioned is the code that i am using to select all the text page by page in RTF.

ActiveDocument.Bookmarks("\Page").Range.Select()

But i observe that it is selecting text from multiple pages.
i.e. text from current page along with (text from previous page or from next page)



Why is that the above code snippet not selecting text only from the current page but also includes text from next page as well ?


Any suggestions to resolve this and ensure text from only the current page is selected.
Reply With Quote
  #2  
Old 11-28-2012, 04:14 AM
macropod's Avatar
macropod macropod is offline Selection of all Text for a specific page in word is spanning selection across pages Windows 7 64bit Selection of all Text for a specific page in word is spanning selection across pages Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Since page content in Word is dependent on the attached printer driver, unless your RTF document uses manual page breaks or Next Section breaks to delineate page boundaries, there is no reason to suppose the RTF pages will be the same as what you'll see in Word. That said, you don't need to select a page to work on it. It's far more effieicient to use range objects, for example:
Code:
Sub Demo()
Dim Rng As Range, i As Long
With ActiveDocument
  For i = 1 To .ComputeStatistics(wdStatisticPages)
    Set Rng = .GoTo(What:=wdGoToPage, Name:=i)
    Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\page")
    With Rng
      'Do something with the page range
    End With
  Next
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 11-29-2012, 01:32 AM
ramsgarla ramsgarla is offline Selection of all Text for a specific page in word is spanning selection across pages Windows 7 64bit Selection of all Text for a specific page in word is spanning selection across pages Office 2010 64bit
Novice
Selection of all Text for a specific page in word is spanning selection across pages
 
Join Date: Sep 2012
Posts: 21
ramsgarla is on a distinguished road
Default

This doesn't seem to be working.
Inspite of implementing the code suggested by you, i still find the text selection is spanning pages in RTF document.

Attached is the screenshot where i am currently in page 3, but it selects
text even from page 2 as well.

How do i get rid of this kind of selection and ensure only text in the current page is selected ?
Attached Images
File Type: gif Text_Selection_Spanning_Pages.GIF (23.2 KB, 21 views)
Reply With Quote
  #4  
Old 11-29-2012, 01:45 AM
macropod's Avatar
macropod macropod is offline Selection of all Text for a specific page in word is spanning selection across pages Windows 7 64bit Selection of all Text for a specific page in word is spanning selection across pages Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

It appears you're working with a table, with cells spanning page boundaries and that merged/split cells are involved. Correct? If so, defining a range that spans all the columns on a given page may be causing the effect.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 11-29-2012, 09:34 PM
ramsgarla ramsgarla is offline Selection of all Text for a specific page in word is spanning selection across pages Windows 7 64bit Selection of all Text for a specific page in word is spanning selection across pages Office 2010 64bit
Novice
Selection of all Text for a specific page in word is spanning selection across pages
 
Join Date: Sep 2012
Posts: 21
ramsgarla is on a distinguished road
Default

So, How do i resolve this issue ?
Any code snippets would be of great help.
Reply With Quote
  #6  
Old 11-29-2012, 10:09 PM
macropod's Avatar
macropod macropod is offline Selection of all Text for a specific page in word is spanning selection across pages Windows 7 64bit Selection of all Text for a specific page in word is spanning selection across pages Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Dealing with this would probably require a fair bit of vba coding. If you can attach a document to a post with some representative data (delete anything sensitive), I'll take a look at it (no promises, though). You can attach files via the paperclip symbol on the 'Go Advanced' tab.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 12-03-2012, 05:38 AM
ramsgarla ramsgarla is offline Selection of all Text for a specific page in word is spanning selection across pages Windows 7 64bit Selection of all Text for a specific page in word is spanning selection across pages Office 2010 64bit
Novice
Selection of all Text for a specific page in word is spanning selection across pages
 
Join Date: Sep 2012
Posts: 21
ramsgarla is on a distinguished road
Default

Attached is the Zip file that has sample RTF document with which, i was trying to select text from each page , but i find text is being selected from current page as well as previous page or next page during the iteration.

Select text from page 2 and 3, you will find text being selected from multiple pages rather than that specific page.

you can use this sample rtf document for your analysis.

Thanks for your help in Advance.
Attached Files
File Type: zip TestData.zip (13.1 KB, 12 views)
Reply With Quote
  #8  
Old 12-03-2012, 03:39 PM
macropod's Avatar
macropod macropod is offline Selection of all Text for a specific page in word is spanning selection across pages Windows 7 64bit Selection of all Text for a specific page in word is spanning selection across pages Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

OK. I've had a quick look at the document and can see what the problem is - cells spanning page boundaries. What is the purpose of the page-by-page processing? Can your needs be met by telling Word to not allow the cells to split across pages?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 12-04-2012, 09:13 PM
ramsgarla ramsgarla is offline Selection of all Text for a specific page in word is spanning selection across pages Windows 7 64bit Selection of all Text for a specific page in word is spanning selection across pages Office 2010 64bit
Novice
Selection of all Text for a specific page in word is spanning selection across pages
 
Join Date: Sep 2012
Posts: 21
ramsgarla is on a distinguished road
Default

My requirement is to generate a report which could range upto 1000 pages
and will have lots of tables in it.

It's a business need that tables having too many rows and which cannot be accommodated in a single page will have to flow to next page and cannot be broken.

So, preventing the cells spanning page boundaries is not desirable.

Having said that, some times, i find an empty table row on a page in RTF file which (as you mentioned) would have got crossed the page boundaries.

My main problem over here,i need to ensure that there are no empty pages or pages with empty table rows in the report. If there are any, then i need to get rid of them by removing these kind of blank pages.

For the same reason, i am iterating through the whole RTF document page by page searching for blank pages and removing them.

I need to achieve this programmatically.

This is where the problem lies, where in it is not able to identify pages with empty table rows or cells, becoz a part of the text gets selected from previous page resulting the current page not to be considered as a blank page. But, actually, it's a blank page.

Any help in resolving this issue would be great.
Reply With Quote
  #10  
Old 12-05-2012, 03:23 AM
macropod's Avatar
macropod macropod is offline Selection of all Text for a specific page in word is spanning selection across pages Windows 7 64bit Selection of all Text for a specific page in word is spanning selection across pages Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

What you could try is cleaning up the table contents. I note that many cells have an empty first paragraph, plus text padding at the end. The following macro cleans up both, thus reducing each table's overall size.
Code:
Sub CleanUp()
Dim Tbl As Table, TblCl As Cell, Rng As Range, RngDel As Range
With ActiveDocument
  For Each Tbl In .Tables
    For Each TblCl In Tbl.Range.Cells
      Set Rng = TblCl.Range
      Rng.End = Rng.End - 1
      Set RngDel = Rng.Characters.Last
      RngDel.Collapse wdCollapseEnd
        Do While Asc(RngDel.Characters.First.Previous) < 33
          If RngDel.Start = Rng.Start Then Exit Do
          RngDel.Start = RngDel.Start - 1
        Loop
      RngDel.Text = vbNullString
      If Rng.Paragraphs.Count > 1 Then
      If Len(Rng.Paragraphs.First.Range) = 1 Then Rng.Paragraphs.First.Range = vbNullString
      End If
    Next
  Next
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Printing a Selection in Word and keeping it in the same place on the page punkrae Word 0 03-29-2012 10:49 AM
Selection of all Text for a specific page in word is spanning selection across pages Text Box Selection GugaBFigueiredo Word 1 01-16-2012 09:04 PM
Macro to populate a text form field based on dropdown selection koloa Word 0 10-20-2011 11:52 AM
Selection of all Text for a specific page in word is spanning selection across pages table spanning multiple pages 'upside down' lj_eco Word Tables 13 07-17-2011 04:39 PM
Selection of all Text for a specific page in word is spanning selection across pages Form Field - Drop down selection causing auto text chesspupil Word VBA 7 05-09-2010 05:43 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:58 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