PDA

View Full Version : Using FeedSource with Envelopes



PNJ
01-25-2007, 03:44 PM
I am trying to get my envelopes feed from tray 1 but the following macro always asked to have the envelopes manuall feed. What am I doing wrong.

Option Explicit
Public Sub PrintEnvelopes()
' Print the Evelopes that are selected

Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim addr As String
Dim retaddr As String
Dim oEnv As Word.Envelope

Dim i As Integer
' Access MSWord
Set oWord = CreateObject("Word.Application")
Set oDoc = oWord.Documents.Add
Set oEnv = oDoc.Envelope
oWord.Visible = False
oEnv.Insert
oEnv.FeedSource = wdPrinterOnlyBin

' Create the return address
retaddr = "Amberlea Presbyterian Church" & vbCr & "1820 Whites Rd." & vbCr _
& "Pickering, Ontario" & vbCr & "L1V 1R8"
' For each area selected make sure it contain a single name and address
' then create and print the envelope
For i = 1 To Selection.Areas.count
If Selection.Areas.Item(i).count = 6 Or Selection.Areas.Item(i).count = 256 Then
addr = Selection.Areas.Item(i).Cells(1).Value & " " _
& Selection.Areas.Item(i).Cells(2).Value _
& vbCr & Selection.Areas.Item(i).Cells(3).Value _
& vbCr & Selection.Areas.Item(i).Cells(4).Value & ", " _
& Selection.Areas.Item(i).Cells(5).Value _
& vbCr & Selection.Areas.Item(i).Cells(6).Value
oEnv.PrintOut Address:=addr, ReturnAddress:=retaddr, Size:="Size 6 3/4", _
AddressFromTop:=InchesToPoints(1.75), FeedSource:=True
Else
' If the selection isn't correct display an error message
MsgBox "Invalid Selection for " & vbCr & Selection.Areas.Item(i).Cells(1).Value
End If
Next i
' Close the MSWord document
oWord.DisplayAlerts = False
oDoc.Close
oWord.DisplayAlerts = True
oWord.Quit
MsgBox "All Done Printing"
End Sub

PNJ
01-26-2007, 11:07 AM
I don't understand the difference but the following code does work.

Option Explicit
Public Sub PrintEnvelopes()
' Print the Evelopes that are selected

Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim addr As String
Dim retaddr As String
Dim oEnv As Word.Envelope

Dim i As Integer
' Access MSWord
Set oWord = CreateObject("Word.Application")
Set oDoc = oWord.Documents.Add
Set oEnv = oDoc.Envelope
oWord.Visible = False

' Create the return address
retaddr = "Amberlea Presbyterian Church" & vbCr & "1820 Whites Rd." & vbCr _
& "Pickering, Ontario" & vbCr & "L1V 1R8"
' For each area selected make sure it contain a single name and address
' then create and print the envelope
For i = 1 To Selection.Areas.count
If Selection.Areas.Item(i).count = 6 Or Selection.Areas.Item(i).count = 256 Then
addr = Selection.Areas.Item(i).Cells(1).Value & " " _
& Selection.Areas.Item(i).Cells(2).Value _
& vbCr & Selection.Areas.Item(i).Cells(3).Value _
& vbCr & Selection.Areas.Item(i).Cells(4).Value & ", " _
& Selection.Areas.Item(i).Cells(5).Value _
& vbCr & Selection.Areas.Item(i).Cells(6).Value
oEnv.Insert
oEnv.FeedSource = wdPrinterOnlyBin
oEnv.Address = addr
oEnv.ReturnAddress = retaddr
oEnv.AddressFromTop = InchesToPoints(1.75)
oEnv.PrintOut Size:="Size 6 3/4", FeedSource:=True
Else
' If the selection isn't correct display an error message
MsgBox "Invalid Selection for " & vbCr & Selection.Areas.Item(i).Cells(1).Value
End If
Next i
' Close the MSWord document
oWord.DisplayAlerts = False
oDoc.Close (wdDoNotSaveChanges)
oWord.DisplayAlerts = True
oWord.Quit
MsgBox "All Done Printing"
End Sub