Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting 1 page at a time in Word 1

Status
Not open for further replies.

Owatonna

Programmer
Jun 1, 2007
9
US
I am trying to write a macro that will convert a Word Document to PowerPoint. The document is generated dynamically by the end user and contains a varying number of pages, as well as several tables with a varying number of rows;

Because of this and because the customers want the ability to edit the text on the slides, the only way I can think of for doing it is to set my page size in the Word document to 6" so the contents of 1 page would fit on a PowerPoint Slide. Then I want to go through the document 1 page at a time, copy it and paste it as ole Object into PowerPoint.

The problem I am having is I can't figure out how to select 1 page in Word using VBA.

Can anyone help me out with this?
 



Hi,

If you're looking for a VBA solution, please post in Forum707.

Skip,
[sub]
[glasses] When a group touring the Crest Toothpaste factory got caught in a large cooler, headlines read...
Tooth Company Freeze a Crowd! and
Many are Cold, but Few are Frozen![tongue][/sub]
 
Tricky. Pages are not really objects in Word. They are derived ranges, and are totally dependent on the printer driver. In other words, a "page" on one machine may not be - and often is not - the same "page" on a different machine.

Even if the two different machines use the same printer! If one is using a different printer driver (but for the same printer), the "pages" can come out differently.

You could move through the document, selecting each page - using the pre-defined bookmark "page" - making a range object of it, and then pass that range object over.

faq219-2884

Gerry
My paintings and sculpture
 
Hi Folks,

Actually, it's not so tricky in this case, since it appears to be wholly within Owatonna's control. And there's no ned to select the pages either! Here's how:
Code:
Sub GetPages()
Dim MyRange As Range
Set MyRange = ActiveDocument.Range(0, 0)
For i = 1 To ActiveDocument.ActiveWindow.Panes(1).Pages.Count
    Set MyRange = MyRange.GoTo(What:=wdGoToPage, Name:=i)
    Set MyRange = MyRange.GoTo(What:=wdGoToBookmark, Name:="\page")
    MsgBox MyRange.Text
Next i
End Sub
Cheers

[MS MVP - Word]
 
Macropod,

Your solution seems to work perfectly. Thanks for your help.
 
After doing some more testing, I found 1 problem with this solution. It occurs when my Word document generates tables that span multiple pages. I have it set up to repeat the header information at the top of each page. For some reason, when I am copying the contents of each page, it isn't including these headers. Is there a way to get these headers copied as well?
 
Hi Owatonna,

You could probably do that by testing whether the 1st character on the page is in a table and, if not on the first row of that table, copy any rows for that table that were set to "heading rows repeat".

Cheers

[MS MVP - Word]
 
I like that idea. How can I tell if the first character on the page is in a table?
 
Hi Owatonna,

To do this, you could select the first character on the page, then test it via:
If Selection.Information(wdWithInTable) = True Then
...
End If


Cheers

[MS MVP - Word]
 
I just learned something new. I think that will work for me. Thanks again for all you help Macropod. I really appreciate it.
 
Hi Owatonna,

Do bear in mind that it's better to do this without using 'Selection'. For example:
If MyRange.Characters(1).Information(wdWithInTable) = True Then
...
End If
will return the same result, and is quicker than having to first select the character you're interested in.

Cheers

[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top