Trying to create Envelope only

C

Carol G

I am creating the word object from Outlook.
I wish to create an envelope Only

I don't know much about the Word object. This sub creates both a document
and the envelope.
Is there any way to create only the envelope?

Thanks
Carol

Sub SingleEnvelopefromContact()

Dim objOutlook As Outlook.Application
Dim ins As Inspector
Dim itm As ContactItem
Dim objWord As Word.Application
Dim objDocs As Word.Documents
Dim addr As String

Set objOutlook = CreateObject("Outlook.Application")
Set ins = objOutlook.ActiveInspector
Set itm = ins.CurrentItem
Debug.Print "Selected item " & ins.Caption
Debug.Print "Item class: " & itm.Class

If itm.Class <> olContact Then
MsgBox "The active Inspector is not a contact item; exiting"
Exit Sub
End If

'Open Word invisibly

Set objWord = CreateObject("Word.Application")

On Error GoTo errhandler
addr = objWord.ActiveDocument.Envelope.Address.Text

errhandler:
'If Err = 5852 Then MsgBox "Add an envelope to the document
'This example creates a new document and adds an envelope with a predefined
delivery address and return address.

addr = itm.FullName & vbCr & itm.HomeAddress
retaddr = "Grant Geddes" & vbCr & "Sutton Group Canwest " _
& vbCrLf & "242, 755 Lk. Bonavista Dr. S.E." _
& vbCr & "Calgary, AB T2J 0N3"
objWord.Documents.Add.Envelope.Insert Address:=addr, ReturnAddress:=retaddr
'objWord.ActiveDocument.ActiveWindow.View.Type = wdPrintView
objWord.Visible = True

End Sub
 
J

Jezebel

IN Word, an Envelope is something attached to a document. What you want to
create is just an envelope-sized document. Set up a template for the
envelope size you are using, then in your code, create a new document using
that template.

Separately, if your code is running in Outlook, why are you instantiating a
new instance of Outlook (CreateObject) ? Why not use the instance you're
running in?
 
C

Carol G

Thanks,
I thought that I had to create a outlook object to create the inspector etc.
I'll try taking it out and looking at how to use the object I already have.
I'm new to both Outlook and Word programming.
So everything is a struggle.

Carol
 
G

Graham Mayor

There are some envelope template samples you can download from my web site
that are automated to collect data from Outlook contacts.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
C

Carol G

Thanks,
I'll do so.
Carol
Graham Mayor said:
There are some envelope template samples you can download from my web site
that are automated to collect data from Outlook contacts.

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