Reply
 
Thread Tools Display Modes
  #1   Report Post  
Sabi S via OfficeKB.com
 
Posts: n/a
Default Mailmerge envelopes from outlook contacts

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

--
Message posted via http://www.officekb.com
  #2   Report Post  
Doug Robbins
 
Posts: n/a
Default

Not sure why you are using code for this rather than the mail merge facility
that is built-in.

--
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
"Sabi S via OfficeKB.com" wrote in message
...
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

--
Message posted via http://www.officekb.com



  #3   Report Post  
Peter Jamieson
 
Posts: n/a
Default

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
"Sabi S via OfficeKB.com" wrote in message
...
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

--
Message posted via http://www.officekb.com



  #4   Report Post  
Sabi S via OfficeKB.com
 
Posts: n/a
Default

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

--
Message posted via http://www.officekb.com
  #5   Report Post  
Peter Jamieson
 
Posts: n/a
Default

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

"Sabi S via OfficeKB.com" wrote in message
...
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...

--
Message posted via http://www.officekb.com


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




  #6   Report Post  
Sabi S via OfficeKB.com
 
Posts: n/a
Default


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

--
Message posted via http://www.officekb.com
  #7   Report Post  
Peter Jamieson
 
Posts: n/a
Default

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

"Sabi S via OfficeKB.com" wrote in message
...

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

--
Message posted via http://www.officekb.com



  #8   Report Post  
Sabi S via OfficeKB.com
 
Posts: n/a
Default

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?

--
Message posted via http://www.officekb.com
  #9   Report Post  
Peter Jamieson
 
Posts: n/a
Default

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

"Sabi S via OfficeKB.com" wrote in message
...
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?

--
Message posted via http://www.officekb.com



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Merge from Outlook Address Book does not show contacts Tomster Mailmerge 1 May 5th 05 05:44 AM
Mail Merge and Outlook Contacts Greg Mailmerge 3 February 23rd 05 07:00 PM
Problems (again) getting Outlook contacts in Word 2002 Mailmerge Carl Mailmerge 1 January 21st 05 02:13 AM
How to print addresses on envelopes from Outlook Contacts data ? JimBo Row Mailmerge 1 December 20th 04 08:04 AM
mailmerge , using outlook contacts both programs close when I cl. Paul Mailmerge 1 December 5th 04 07:56 AM


All times are GMT +1. The time now is 12:30 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"