Possible to create TXT for every page in DOC file?

S

scottmmckay

Hi I'm new to VBA and I'm not sure if this can be done...


I have over 80 *.doc files and they have anywhere from 50 to 1000
pages in them, and I need to find a way to export a TXT file for each
page break


is there any sort of macro that can do this?



any help or advice would be greatly apriciated, thanks!
 
L

larrysulky

Scott, I was hoping someone else more knowledgeable than I would reply.
But I'll at least get the ball rolling. Such a thing is doable using
ranges. Are these pages separated by inserted page breaks? Or it's just
wherever the page happens to break that sets the boundary for an
individual text document?
--larry
 
G

Graham Mayor

How successful this will be depends on what is on the page. Word is not a
page layout application.
The following macro will split by page to text files which it will save in
the folder indicated at docname - change that to where you want them to be
saved.

Sub SplitByPage()

Dim mask As String
Letters = ActiveDocument.Bookmarks("\page").Range
mask = "ddMMyy"

Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter < Letters
Application.ScreenUpdating = False
sName = "Split"
Docname = "D:\My Documents\Test\Merge\" _
& sName & " " & Format(Date, mask) & " " & LTrim$(Str$(Counter)) &
".txt"
On Error GoTo oops:
ActiveDocument.Bookmarks("\page").Range.Cut
Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDOSText
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
oops:
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

Doug Robbins - Word MVP

Use the following code to split each document.

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) & ".txt"
Source.Bookmarks("\Page").Range.Cut
Set Target = Documents.Add
Target.Range.Paste
Target.SaveAs FileName:=DocName, FileFormat:=wdFormatText
Target.Close
Wend

--
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
 

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