Count tables for each page

V

Vale

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! :)
 
G

Greg Maxey

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.
 
V

Vale

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
 
V

Vale

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top