Discussion:
Read word document text page-by-page
(too old to reply)
Dana
2005-12-12 12:20:01 UTC
Permalink
Hi

Is there any method by which I can read a word file from my VB application
page-by-page?

Currently, I can open the file and save the text as a text file, but what I
need is a way to know the page numbers, so I though instead of saving the
text as a text file, I might be able to read the text from the word file
page-by-page and add the page numbers then save the text to a text file.




Any ideas?


Dana
Doug Robbins - Word MVP
2005-12-12 21:01:09 UTC
Permalink
Use a modification of the following:

Sub splitter()

'

' splitter Macro

' Macro created 16-08-98 by Doug Robbins to save each page of a document

' as a separate file with the name Page#.DOC

'

Dim Counter As Long, Source As Document, Target As Document

Set Source = ActiveDocument

Selection.HomeKey Unit:=wdStory

Pages = Source.BuiltInDocumentProperties(wdPropertyPages)

Counter = 0

While Counter < Pages

Counter = Counter + 1

DocName = "Page" & Format(Counter)

Source.Bookmarks("\Page").Range.Cut

Set Target = Documents.Add

Target.Range.Paste

Target.SaveAs FileName:=DocName

Target.Close

Wend

End Sub
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
Post by Dana
Hi
Is there any method by which I can read a word file from my VB application
page-by-page?
Currently, I can open the file and save the text as a text file, but what
I need is a way to know the page numbers, so I though instead of saving
the text as a text file, I might be able to read the text from the word
file page-by-page and add the page numbers then save the text to a text
file.
Any ideas?
Dana
Loading...