PDA

View Full Version : ActiveDocument.ActiveWindow.Panes(1).Pages.Count



DEWunderlich
05-17-2008, 09:44 PM
I am going through a Word document and selecting each page so I can copy and paste into a PowerPoint presentation. I am using ActiveDocument.ActiveWindow.Panes(1).Pages.Count to determine how many pages I have. I set up a loop like this to go through the document:

for i = 1 to ActiveDocument.ActiveWindow.Panes(1).Pages.Count
Set myRange = myRange.GoTo(What:=wdGoToPage, Name:=i)
....

For some reason, it says the pages.count value for my test document is 40, but when I step through it, it gets to 40 with 2 or 3 pages left, so the last pages don't get copied. If I set i higher than 40 in the immediate window while debugging, it finds the remaining sections. Does anyone know why this would be happening or what I can do to resolve it?

shasur
05-21-2008, 03:04 AM
Hi

Can you try

ActiveDocument.range.Information(wdNumberOfPagesInDocument)

Cheers
Shasur

gwkenny
05-21-2008, 05:58 AM
I don't know, if you could paste a copy of the file (taking out your confidential information and replacing it with junk) that would be helpful.

Could be a corrupt section break. Could be that the last few pages are appendixes and are separated with a section break that starts renumbering the pages from 1 again. Word code is pretty fickle in that respect and you would have to include the section as well.

But just examining the line:

Set myRange = myRange.GoTo(What:=wdGoToPage, Name:=i)

is confusing. myRange is defined somewhere. You redefine myRange as to be the beginning of a certain page number. Then you loop through again. Is myRange being redefined somewhere again? Or is this really working cause logically it does not hold for me.

fumei
05-21-2008, 11:45 AM
I agree.

Unless myRange has been previous Set, then:


Set myRange = myRange.GoTo(What:=wdGoToPage, Name:=i)

would return an error.