Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

Count tables for each page

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vale - 25 Oct 2006 17:21 GMT
Hi!

I would count how many tables are present in each page of my document Word

I tried this:

Dim pagine As Integer = Wordoc.ActiveWindow.ActivePane.Pages.Count
       Dim p As Integer
       Dim sel As Word.Range
       sel = Wordoc.Bookmarks("\Page").Range
       Dim tabelle As Integer

       For p = 1 To pagine

           tabelle = sel.Tables.Count

           Tab_box.Text = ("Pagina" & p & "tabelle" & tabelle)

           sel = sel.GoToNext(WdGoToItem.wdGoToPage)

       Next

but i have problems to go to the next page

the count of the first page is right the second gives me 1 table in the
second page (When there are 9 tables) i don't understand why
Help me please!
Thanks! :-)
Greg Maxey - 25 Oct 2006 17:37 GMT
This is problematic because a Word page isn't actually a page until it
is displayed on a screen or printed on paper.  That done, pages shown
on my screen or from my printer may very well be different that those
shown on yours.  For an excellent explanation of all of this see:
http://daiya.mvps.org/wordpages.htm

That said, a crude method, and with limitations would look something
like this:

Sub ScratchMacro()
Dim oRng1 As Word.Range
Dim oCount As Long
ActiveDocument.Bookmarks("\startofdoc").Select
Set oRng1 = Selection.Range
Do
 Set oRng1 = ActiveDocument.Bookmarks("\Page").Range
 oCount = oRng1.Tables.Count
 MsgBox "There are " & oCount & " Tables on this page"
 oCount = 0
 oRng1.Collapse wdCollapseEnd
 oRng1.Move wdCharacter, 1
 oRng1.Select
Loop Until oRng1.End = ActiveDocument.Range.End - 1
End Sub

It would take more work to prevent tables that span accross a page from
being counted as as a separate table on each page.

> Hi!
>
[quoted text clipped - 24 lines]
> Help me please!
> Thanks! :-)
Vale - 25 Oct 2006 18:04 GMT
thank you for your help

I'm trying your "crude method" but in
oRng1.Move wdCharacter, 1
I must specificate the object wdChararcter
so i wrote
Dim cha as Word.wdCharactercase=..... what's case?

and sorry for my question:

the method Move() as you wrote it , it's ok for my use?
better move the range to the next page?
thank you

> This is problematic because a Word page isn't actually a page until it
> is displayed on a screen or printed on paper.  That done, pages shown
[quoted text clipped - 52 lines]
> > Help me please!
> > Thanks! :-)
Vale - 25 Oct 2006 18:30 GMT
your crude method modified work!

don't read my previous post

I've found the right function to go to the next page

I wrote
oRng1.GoToNext(WdGoToItem.wdGoToPage)
instead of
oRng1.Move wdCharacter, 1

now I can go on with my program!

THAK YOU VERY MUCH! :-D

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.