Select Multiple pages from a Word document ...

G

Gopi

Hello All,

I am facing difficulty in copying a range of pages from an MS word document.
Say, I have a document comprising of 50 pages and I want to select the first
20(1 to 20 pages) from the word document using VBA in MSExcel. Can someone
pls help me out in resolving the same.

P.S: I am using Office 2000 as my development environment.

Regards,
Gopi
 
B

Brian

I don't know how you call word from excel, but the following works in Word. I
commented out the lines that paste into a new document.

Sub CopyPages()
'
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="21"
With Selection
.EndKey Unit:=wdLine, Extend:=wdExtend
.MoveUp Unit:=wdLine, Count:=1
.HomeKey Unit:=wdStory, Extend:=wdExtend
.Copy
'Documents.Add DocumentType:=wdNewBlankDocument
'Selection.PasteAndFormat (wdPasteDefault)
End With
End Sub

Hope this is of some help.
 
H

Helmut Weber

Hi Gopi,

Sub Test444()
' early binding, Word already running
' sourcedocument open
' sourcedocument is active document
Dim oWrd As Word.Application
Dim oDoc As Word.Document
Set oWrd = GetObject(, "Word.Application")
Set oDoc = oWrd.ActiveDocument
oDoc.Range(0, 0).Select
With oWrd
.Selection.ExtendMode = True
.Selection.Goto _
what:=wdGoToPage, _
which:=wdGoToAbsolute, _
Count:=21 '!
' MsgBox .Selection.Information(wdActiveEndPageNumber)
.Selection.Copy
' your code
End With
End Sub

Brian's solution is quite alright was well.

@ Brian:

With the exception, that
....
.EndKey Unit:=wdLine, Extend:=wdExtend
.MoveUp Unit:=wdLine, Count:=1
....
should be
....
.MoveUp Unit:=wdLine, Count:=1
.EndKey Unit:=wdLine, Extend:=wdExtend
....

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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