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 / Mailmerge and Fax / July 2005

Tip: Looking for answers? Try searching our database.

Mailmerge envelopes from outlook contacts

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sabi S - 22 Jun 2005 15:06 GMT
can sum1 show me the code for this..My code is as follows:I am able to
retrieve contacts but print only 1 envelope not multiple please help me...

   Set myOlApp = CreateObject("Outlook.Application")
   Set objWordApp = CreateObject("Word.Application")
   Set objWordDoc = objWordApp.Documents.Add
   objWordDoc.MailMerge.MainDocumentType = wdEnvelopes

  For i = 1 To fldFolder.Items.Count
 
       Set Contact = Outlook.Session.GetDefaultFolder(10).Items(i)
       a = Contact.Email1Address
       If bb = True Then
           For k = 0 To List1.ListCount - 1
               If a = List1.List(k) Then
                   r = Contact.FullName
                   v = Contact.BusinessAddress
               
'addr has the size of envelope
addr = Combo1.Text
ice = Left(addr, Len(addr) - InStr(addr, "("))
sp = Trim(ice)
objWordDoc.Envelope.DefaultSize = sp
objWordDoc.MailMerge.DataSource.FindRecord (a)
objWordDoc.Envelope.Insert Address:=r & Chr(10) & v, ReturnAddress:
=txtAddress.Text
With objWordDoc.MailMerge
       .Destination = wdSendToNewDocument
       .SuppressBlankLines = True

End With
objWordDoc.ActiveWindow.View.Type = wdPrintView
objWordApp.WindowState = wdWindowStateMaximize

       End If
       Next k
       End If
   Next i
Doug Robbins - 22 Jun 2005 17:56 GMT
Not sure why you are using code for this rather than the mail merge facility
that is built-in.

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

> can sum1 show me the code for this..My code is as follows:I am able to
> retrieve contacts but print only 1 envelope not multiple please help me...
[quoted text clipped - 34 lines]
>        End If
>    Next i
Peter Jamieson - 22 Jun 2005 18:26 GMT
At the moment you do not seem to be doing a .Execute for the merge. If the
envelope is supposed to be printed directly as a result of the merge, you
would need to use wdSendToPrinter rather than wdSendToNewDocument.
Otherwise, you need to think about either printing and removing the output
document, or giving the output document a name, closing it, etc.

Peter Jamieson
> can sum1 show me the code for this..My code is as follows:I am able to
> retrieve contacts but print only 1 envelope not multiple please help me...
[quoted text clipped - 34 lines]
>        End If
>    Next i
Sabi S - 24 Jun 2005 06:19 GMT
I have tried using mailmerge.execute but it gives me an error saying it needs
a datasource..pls help me as I am badly stuck with this 4 a long period...

Thx in advance...
Peter Jamieson - 24 Jun 2005 09:26 GMT
Hi,

Actually I had assumed you had already set up a datasource, but now I look
at your code again, I see that you have not.

I agree with Doug that there is a simple manual process that allows you to
merge from Outlook.

If you have to automate, there are at least two major problems:
a. you cannot actually automate Outlook's Mail Merge feature because there
is no equivalent method in the Outlook Object model
b. you cannot (easily) automate a connection from Word to Outlook using
Word's OpenDataSource method because when you try to connect in the same way
that Word connects, you will always see a dialog box asking you to choose a
Contacts folder.

In your case, you appear to be having to do something special with your
Contact data. Unfortunately, I cannot tell what it is from your code
because, for example, I do not know what List1 is. As far as I can tell, you
are trying to produce multiple envelopes for each contact in an Outlook
Contacts folder. If so, it is probably easier to do one of the following
things:
a. Divide your processing into two steps:
1. create an output file and output one record to it for each envelope
2. start Word and either
 - open a pre-existing mail merge main document that already knows where
the output file in (1) is, and execute the merge or
 - create an envelope merge, use OpenDataSource to connect it to the file
you created in (1), insert the necessary MERGEFIELD fields, and perform the
merge
b. Do not use Merge.
1. Create a Word document with an envelope layout, perhaps with {
DOCPROPERTY } fields where you want to put your data
2. start Word and open that document
3. for each envelope, use Word automation to insert the data for the
envelope directly into the envelope, or set the values of the document
variables you created in (1), setting any zero-length strings to a space "
". Then print the envelope or save it to an output file.

If you use approach (b) you may find some useful sample code at
http://www.slipstick.com

If I have misuunderstood what you are trying to do, can you please go
through it step by step?

Peter Jamieson

>I have tried using mailmerge.execute but it gives me an error saying it
>needs
> a datasource..pls help me as I am badly stuck with this 4 a long period...
>
> Thx in advance...

  Set myOlApp = CreateObject("Outlook.Application")
   Set objWordApp = CreateObject("Word.Application")
   Set objWordDoc = objWordApp.Documents.Add
   objWordDoc.MailMerge.MainDocumentType = wdEnvelopes

  For i = 1 To fldFolder.Items.Count

       Set Contact = Outlook.Session.GetDefaultFolder(10).Items(i)
       a = Contact.Email1Address
       If bb = True Then
           For k = 0 To List1.ListCount - 1
               If a = List1.List(k) Then
                   r = Contact.FullName
                   v = Contact.BusinessAddress

'addr has the size of envelope
addr = Combo1.Text
ice = Left(addr, Len(addr) - InStr(addr, "("))
sp = Trim(ice)
objWordDoc.Envelope.DefaultSize = sp
objWordDoc.MailMerge.DataSource.FindRecord (a)
objWordDoc.Envelope.Insert Address:=r & Chr(10) & v, ReturnAddress:
=txtAddress.Text
With objWordDoc.MailMerge
       .Destination = wdSendToNewDocument
       .SuppressBlankLines = True

End With
objWordDoc.ActiveWindow.View.Type = wdPrintView
objWordApp.WindowState = wdWindowStateMaximize

       End If
       Next k
       End If
   Next i
Sabi S - 28 Jun 2005 10:29 GMT
Lets go by ur statements:
In the first instance u tell me i cannot automate with mail merge feature and
with OpenDataSource method also it won't connect.I have tried to understand
this but when it comes to my code ..u r askin me to use mail merge ...how is
that possible??

My code :

I create an envelope document.'i' loops through all contacts in contact
folder and in list1..I have a list of email addresses on my interface for the
user to select to create envelopes for that many addresses.
So when 'a' i.e contact.email1address from contacts folder matches 'k' i.e
selected addresses by the user..it goes in the loop and creates an envelope
for all the addresses selected but the final output is only one envelope
which overwrites all the address and gives me one envelope with the last
email address selected..this loop works perfectly in terms of inserting
addresses in the envelope document but does not create multiple envelopes
accordingly..how to go about it???..pls give me the code..if I use mailmerge.
execute it gives an error..without mailmerge thr is no way to add envelopes..
Pls help me out...thx in advance...
Peter Jamieson - 28 Jun 2005 13:56 GMT
> Lets go by ur statements:
> In the first instance u tell me i cannot automate with mail merge feature
[quoted text clipped - 4 lines]
> is
> that possible??

My suggestion was that you export your data from Outlook and then use the
exported data as the data source. so that you no longer have to connect
directly to Outlook. That way, a mailmerge is feasible.

But if you do not have to use mailmerge, there is probably a better way...

> without mailmerge thr is no way to add envelopes..

You can try using

ActiveDocument.Envelope.Insert

which allows you to add an address and return address. Then you would need
to print or save the document.

Unfortunately I'm about to go away so cannot follow this up, but if you look
in Word VBA help for the Envelope object you should find at least one
example.

Peter Jamieson

> Lets go by ur statements:
> In the first instance u tell me i cannot automate with mail merge feature
[quoted text clipped - 23 lines]
> envelopes..
> Pls help me out...thx in advance...
Sabi S - 28 Jun 2005 18:20 GMT
do I understand tht mail merge cannot be performed as to creating multiple
envelopes and tht for evry address inserted should get printed or saved
individually in a new document..thx 4 ur feedback...any comments?
Peter Jamieson - 06 Jul 2005 08:29 GMT
Sorry for the delayed reply.

You can use mailmerge to produce multiple envelopes, either to an output
file or to printer. I have just done an envelope merge here.

However, it is up to you to test the merge in the "production" environment,
i.e. with the PC, printer, version of Word, and the data source you intend
to use. In particular, you need to ensure that the printer loads the
envelopes from the tray you expect (and you may need to change some settings
in File|Page Setup), and prints the right way around.

Peter Jamieson

> do I understand tht mail merge cannot be performed as to creating multiple
> envelopes and tht for evry address inserted should get printed or saved
> individually in a new document..thx 4 ur feedback...any comments?
 
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.