Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save multiple merged letters as individual documents

Status
Not open for further replies.

topdesk123

Programmer
Sep 27, 2001
76
US
Hi!

I have a form template that will be merged with data from an Excel spreadsheet. I need to save each form with a separate specific name based on the data (ie. [Agency Name]_Agency Administrator_Add Removal_Form.doc). The form also has form controls that become inactive when I merge. Can anyone point me in the right direction?

Thanks so much!
topdesk123
 
Thank you Peter! I have read that and tried it numerous times but continue to get the error "The selection does not consist of heading levels". I have set the first line to Level 1 - even tried the whole paragraph. Any other thoughts?

topdesk
 
Hi,

This may be of some help:

Is is possible to save each page in a word document as a new document? For example I have a document called testdoc with 250 pages. What I want to do is automatically save each individual page as a new document. So page 1 would be testdoc1.doc and page 2 would be testdoc2.doc and so on. I am not that picky about how it is named.

Thanks
Dodge20

fumei (TechnicalUser) Jun 3, 2004

Yes. The following creates individual files for each page of a document. It add "Pagepagenumberof" to the original filename, and saves them into the same folder holding the original file. So page 4 of "test.doc" will be saved as "Page4oftest.doc"

NOTE: this creates a document for every page, including blank ones. It could be tweaked to determine blank pages.


CODE

Sub EachPageDoc()

Dim aDoc As Document
Dim lngPageCount As Long, lngCurrentPage As Long
Dim var As Variant

Set aDoc = ActiveDocument
lngCurrentPage = 1
' use constant for number of pages
lngPageCount = aDoc.BuiltInDocumentProperties(14)

' turn off screen updating otherwise
' your brain will turn into mush
Application.ScreenUpdating = False

' go to top of doc
Selection.HomeKey Unit:=wdStory
For var = 1 To lngPageCount

' make selection of page, and copy it
aDoc.Bookmarks("\page").Select
Selection.Copy

' make new document, paste, and save
Application.Documents.Add
Selection.PasteSpecial
ActiveDocument.SaveAs FileName:=aDoc.Path & _
Application.PathSeparator & "Page" & lngCurrentPage & "of" & aDoc.Name
ActiveDocument.Close


' go to next page
aDoc.Activate
Selection.GoTo what:=wdGoToPage, Which:=wdGoToNext, Count:=1, Name:=""
lngCurrentPage = lngCurrentPage + 1
Next

' turn screen update back on
Application.ScreenUpdating = True

' release aDoc
Set aDoc = Nothing

MsgBox "Done."
End Sub

Hope this helps.

Gerry

dodge20 (MIS) Jun 3, 2004

This is real close, for every page it puts a blank page after it. Can this be eliminated? Also is it possible to save it as a .txt file?

Here is a star for your efforts so far.
Dodge20

dodge20 (MIS) Jun 3, 2004

2 things to add to my last post. It looks like it just has 1 blank line after each page which causes the new blank page. Also if I can get it to save a .txt then it will eliminate the extra pages altogether.
Dodge20

Good Luck!
Peter Moran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top