PDA

View Full Version : name files after mail merge



tom7w
09-30-2005, 07:38 AM
Hi
I have the Excel file and Word file for mail merge, after mail merge, I separte each page using Dreamboat knowledge base entry
http://vbaexpress.com/kb/getarticle.php?kb_id=139
Now, I would like to name each file using the street name and fax number (faxnbr).
humm, I am not sure how to attach Excel and Word to this message.!!!
please look at the attached zip file: mailmergeExcelWord.zip
If you cannot open it, please let me know, this is my first time zipping files.

The outcome four filenames should be something similar to the followings:
first filename: main128-238-2222
second filename: south 14th879-888-8777
third filename: 3rd ave N128-773-8348
fourth filename:US301 N951-873-8484
does not have to be exactly like the above, but something that has street name and faxnumber are good enough.
I really appreciate all the help, all great volunteers.

Sincerely
Tom

MOS MASTER
09-30-2005, 04:20 PM
Hi and Welcome to VBAX Tom! :hi:

I think what you mean is use some of the mergefield information to build your pathname (document name) right?

If so then I think that KB is not the right way to go for you cause you allready merged your document.

I think it's much wiser to let the code do the merge for you and merge each document in to it's rightfull path with the field information used for the pathname.

That way the code is much more efficient.

If you like that approach I'll give you a example. :whistle:

tom7w
10-01-2005, 02:13 PM
Yes,
say in my Excel I have column for street name and zipcode, and a lot more
I do mail merge, at the end of mail merge I click on create new document button.
I will have a document each page/section is a Word letter with each row of Excel file.
So this is a very long document if The Excel has a lot of rows.
So I would like to break this new document into smaller/individual page/section into smaller files and automated the process by naming the file using the row cell of Excel file.
Please give me an example of your suggestions.
My results are for each row in the Excel I will have a separate file, instead a huge Word document file. Thank you for your help, I really appreciate it.

tom7w
10-03-2005, 12:45 PM
would you please give me an example for let the code do the merge..

kane
03-29-2006, 12:54 PM
I could use this code too, if posted.

Thx,

mdmackillop
03-29-2006, 01:08 PM
Have a look at this KB item
http://vbaexpress.com/kb/getarticle.php?kb_id=290

kane
03-29-2006, 01:19 PM
Is there any way to change the following code so it names the file the content of column A?



Option Explicit

Sub AllSectionsToSubDoc()

Dim x As Long
Dim Sections As Long
Dim Doc As Document

Application.ScreenUpdating = False
Application.DisplayAlerts = False

Set Doc = ActiveDocument
Sections = Doc.Sections.Count
For x = Sections - 1 To 1 Step -1
Doc.Sections(x).Range.Copy
Documents.Add
ActiveDocument.Range.Paste
ActiveDocument.SaveAs (Doc.Path & "\" & x & ".doc")
ActiveDocument.Close False
Next x

Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub