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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MAIL MERGE and SAVE EACH DOCUMENT SEPARATELY 1

Status
Not open for further replies.

PWD

Technical User
Jul 12, 2002
823
GB
Good afternoon, I have looked at:-
FAQ68-5187 How to MAIL MERGE and SAVE EACH DOCUMENT SEPARATELY
And at thread707-858311 but it’s not quite what I need for my people. Basically I want to be able to take my (Master, if you will) Mailmerge document and output it 1 record at a time to new documents that are the result of the Mailmerge rather than just a copy of that (Master) document, complete with its links and macro.
I thought about something like
Code:
                For y = 1 To ActiveDocument.Fields.Count
                ActiveDocument.Fields(y).Unlink
                Next y
But, of course, then there’d be no fields for the next record :(!
Even then there appears to be more fields in the document than fields.count !! ??
As for saving the file without macros……….. pffffff.
I had thought about saving the files (there are 35 records) then opening each one & trying to unlink the fields that way. But each one seems to take an age as it has to re-establish the link to the merge data for each one.
Bit stumped at the moment; any ideas, please?


Many thanks,
D€$
 

hi,
output it 1 record at a time to new documents
That's what the first FAQ does.
Code:
ActiveDocument.SaveAs x & .ActiveRecord & ".doc"
YOU must somehow supply the SaveAs document name, if you don't like the .ActiveRecord value.

What is the issue?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hi Skip. My SaveAs looks like this now:-
Code:
ActiveDocument.SaveAs TargetDirectory & .DataFields("SERNO").Value & ".doc"
which is fine as it does save every record in a new document - named as the value of each record's data field "SERNO" - in my location 'TargetDirectory' on the network. The trouble is that each document is still linked to the Excel data source of the 'Master' mailmerge document & they contain the macro that I'm using to split them up. OK, I suppose I could run the code from my Normal.dot but I wanted the document to be shared and used by person or persons unknown(!)

So, I want to be able to unlink each mailmerge field (14 in total) for each document, and also save it without the macro. I suppose I need the original document to keep on reopening and looping though each record?

Many thanks,
D€$
 



You could save all.

Then post process each file in the TargetDirectory, decoupling.

If you have Word 2007+ you can SaveAs a macro free document .docx

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Oh, yes meant to put that. I've got 2007 on the CITRIX server (now) & 2010 on my laptop when I'm in the office. I've used the 'Export' facility to produce pdf's from Excel recently. Would that be a viable option?

Many thanks,
D€$
 
Is there a quick way to unlink all the fields? As when I try using the
Code:
                AFCount = ActiveDocument.Fields.Count
                For y = 1 To AFCount
                ActiveDocument.Fields(y).Unlink
                Next y
it errors as if the fields aren't numbered/created sequentially, e.g. it will error looking for Field(8) or Field(9)

Many thanks,
D€$
 


Code:
ActiveDocument.Fields.Unlink


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks, I'll try that.

Des.

Many thanks,
D€$
 
Awesome!! I'll post my code when I've got it doing what I want doing done!

Many thanks,
D€$
 
Code:
   With ActiveDocument.MailMerge.DataSource
      .ActiveRecord = 1
      Do Until .ActiveRecord = .RecordCount
         .ActiveRecord = wdNextRecord
         ActiveDocument.Fields.Unlink
         Convert_2_PDF
        
         'Need to undo previous 'Unlink' action, then continue
         
      Loop
   End With

Sub Convert_2_PDF()


ActiveDocument.ExportAsFixedFormat _
OutputFileName:=ActiveDocument.Path & "\" & Left(ActiveDocument.Name, _
Len(ActiveDocument.Name) - 4) & ".pdf", ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, Item:=wdExportDocumentContent, _
IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:=wdExportCreateNoBookmarks, _
DocStructureTags:=True, BitmapMissingFonts:=True, UseISO19005_1:=False


End Sub

Many thanks,
D€$
 
Code:
ActiveDocument.Undo

Many thanks,
D€$
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top