Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2006

Tip: Looking for answers? Try searching our database.

Mail Merge on Labels with Matrix Printer from txt file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Johannes Schmitz - 24 Mar 2006 20:53 GMT
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
Doug Robbins - Word MVP - 25 Mar 2006 08:29 GMT
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

Signature

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

> Hello,
> I am working on the following project:
[quoted text clipped - 9 lines]
>
> Greeting, Johannes
Johannes Schmitz - 25 Mar 2006 18:09 GMT
Thank you, I will try this and ask if I need more help.

Johannes
Johannes Schmitz - 25 Mar 2006 18:22 GMT
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
Johannes Schmitz - 25 Mar 2006 18:51 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.