Mail Merge on Labels with Matrix Printer from txt file

J

Johannes Schmitz

Hello,
I am working on the following project:
I have to print a mail merge on Labels from a table in form of txt.
This txt file does not contain column headings, which apparently already
represents a problem with Word.
I would like to write a Script, so that the user only has to select the
concerned txt file in a form then the mail merge is provided and one can
print.
Who can help me or explain at least roughly the proceeding?

Sorry for my english

Greeting, Johannes
 
D

Doug Robbins - Word MVP

I assume that when you say "user only has to select the concerned txt file
in a form", you mean that when the user has the Label type mailmerge main
document open, they only have to select the data source by using something
like the file open dialog.

If that is the case, the following will probably do what you want, though
you may have to alter the text that is being inserted into the text document
so that the field names and the separators are appropriate for your
situation:

Dim opened As Boolean
Dim maindoc As Document, source As Document
Dim sourcename As String
Set maindoc = ActiveDocument
If maindoc.MailMerge.MainDocumentType <> wdMailingLabels Then
MsgBox "The active document is not a label type mailmerge main
document."
Exit Sub
End If
opened = Dialogs(wdDialogFileOpen).Show
If opened = False Then
MsgBox "You pressed cancel."
Exit Sub
End If
Set source = ActiveDocument
sourcename = source.FullName
If UCase(Right(sourcename, 3)) <> "TXT" Then
MsgBox "The file that you opened is not a text file."
Exit Sub
End If
source.Range.InsertBefore "first,last,address,city,postcode" & vbCr
'modification may be required
source.Save
source.Close
With maindoc.MailMerge
.OpenDataSource Name:=sourcename
.Destination = wdSendToPrinter
.Execute
End With


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

Johannes Schmitz

I tried to run the code but i get an error. (in Line 4, something with
Procedure) Can you explain me what i have to do in order to run this?

Johannes
 
J

Johannes Schmitz

Ok, finally I got it running.
My next question is if it is possible to save the txt file as an excel file
inside the makro. And than use the excel file as Datasource.

Johannes
 

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