mail merge macro or script

T

Ted

I have a mail merge document and need a macro or script that will go through
all the mail merge records and save each record as it's own document using
one of the mail merge fields as the document name. Is this possible?
 
T

Ted

This is perfect, thank you. I was wondering if there is a way to have it save
each of the separate documents with a different extension like a basic .txt
file.
 
D

Doug Robbins - Word MVP

You could modify the code to do that.

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

Ted

I understand that and did try to modify the code before posting but couldn't
get it to do what I wanted. I am not that good with code which is why I
posted the question here.
 
G

Graham Mayor

Rather than mess up the add-in - use the following macro to batch save all
the documents as TXT

Sub SaveAllAsTXT()
Dim strFileName As String
Dim strDocName As String
Dim strPath As String
Dim oDoc As Document
Dim Response As Long
Dim fDialog As FileDialog

Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)

With fDialog
.Title = "Select folder and click OK"
.AllowMultiSelect = False
.InitialView = msoFileDialogViewList
If .Show <> -1 Then
MsgBox "Cancelled By User", , "Save all as TXT"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) <> "\" Then strPath = strPath + "\"
End With

If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If

strFileName = Dir$(strPath & "*.doc")

While Len(strFileName) <> 0
Set oDoc = Documents.Open(strPath & strFileName)

strDocName = ActiveDocument.FullName
intPos = InStrRev(strDocName, ".")
strDocName = Left(strDocName, intPos - 1)
strDocName = strDocName & ".txt"
oDoc.SaveAs FileName:=strDocName, _
FileFormat:=wdFormatDOSText
oDoc.Close SaveChanges:=wdDoNotSaveChanges
strFileName = Dir$()
Wend
End Sub


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
T

Ted

I copied the text and created a new macro in a new document. When I run the
macro it does prompt me for the folder location, but when I click ok it
doesn't do anything. It closes the document and doesn't resave allt he files
in the folder. I'm not sure what I am doing wrong. Any help would be greatly
appreciated.
 
G

Graham Mayor

Is the macro in the document that Word closes? Put it in your normal
template - see http://www.gmayor.com/installing_macro.htm

Do the documents in the folder have the extension doc? The macro only works
with doc files as written.

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