Adam -
Here is some code you can use. I'm not terribly impressed with it, but it
works. Call the routine with:
ParseWordDoc(So urceFilename, DestinationFile name)
Where SourceFilename is the file you are going to extract pages from, and
DestinationFile name is the the base filename you are going to create; for
instance, "Page" would create Page1.doc, Page2.doc, Page3.doc, etc.
The actual code to do the work:
Private Sub ParseWordDoc(By Val Filename As String, ByVal NewFileName As
String)
Dim WordApp As Microsoft.Offic e.Interop.Word. Application = New
Microsoft.Offic e.Interop.Word. Application
Dim BaseDoc As Microsoft.Offic e.Interop.Word. Document
Dim DestDoc As Microsoft.Offic e.Interop.Word. Document
Dim intNumberOfPage s As Integer
Dim intNumberOfChar s As String
Dim intPage As Integer
'Word Constants
Const wdGoToPage = 1
Const wdStory = 6
Const wdExtend = 1
Const wdCharacter = 1
'Show WordApp
WordApp.ShowMe( )
'Load Base Document
BaseDoc = WordApp.Documen ts.Open(Filenam e)
BaseDoc.Repagin ate()
'Loop through pages
intNumberOfPage s = BaseDoc.BuiltIn DocumentPropert ies("Number of
Pages").value
intNumberOfChar s = BaseDoc.BuiltIn DocumentPropert ies("Number of
Characters").va lue
For intPage = 1 To intNumberOfPage s
If intPage = intNumberOfPage s Then
WordApp.Selecti on.EndKey(wdSto ry)
Else
WordApp.Selecti on.GoTo(wdGoToP age, 2)
Application.DoE vents()
WordApp.Selecti on.MoveLeft(Uni t:=wdCharacter, Count:=1)
End If
Application.DoE vents()
WordApp.Selecti on.HomeKey(wdSt ory, wdExtend)
Application.DoE vents()
WordApp.Selecti on.Copy()
Application.DoE vents()
'Create New Document
DestDoc = WordApp.Documen ts.Add
DestDoc.Activat e()
WordApp.Selecti on.Paste()
DestDoc.SaveAs( NewFileName & intPage.ToStrin g & ".doc")
DestDoc.Close()
DestDoc = Nothing
WordApp.Selecti on.GoTo(wdGoToP age, 2)
Application.DoE vents()
WordApp.Selecti on.HomeKey(wdSt ory, wdExtend)
Application.DoE vents()
WordApp.Selecti on.Delete()
Application.DoE vents()
Next
BaseDoc.Close(F alse)
BaseDoc = Nothing
WordApp.Quit()
WordApp = Nothing
End Sub
End Class
"Adam Faulkner via DotNetMonster.c om" <u3667@uwe> wrote in message
news:5a709aa6d8 961@uwe...
I want to create a method within a class that opens a Microsoft Word 2000
Document and has the facility to Create a new word document and then
extract
a Page that exists within the original Word Document and save it to a new
Word Document.
I would need to generate a loop for each page found within a word document
to
create a new word document and insert the existing page into the new word
document and then save as a new word document.
Any recommendations would be appreciated.
Regards
Adam Faulkner
Croner Software
--
Message posted via DotNetMonster.c om
http://www.dotnetmonster.com/Uwe/For...b-net/200601/1