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 / July 2007

Tip: Looking for answers? Try searching our database.

Select Multiple pages from a Word document ...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gopi - 04 Jul 2007 11:02 GMT
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
Brian - 04 Jul 2007 12:04 GMT
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.
Signature

Brian McCaffery

> Hello All,
>
[quoted text clipped - 7 lines]
> Regards,
> Gopi
Helmut Weber - 04 Jul 2007 16:06 GMT
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
...

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

 
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.