Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

outllook script/vba

Status
Not open for further replies.

rowingengineer

Structural
Jun 18, 2009
2,468
I am trying to get outlook to print my emails upon sending if i wish, but i wuold like to be able to choose the print properties, here is my code, anyone know where I have gone wrong?
I want to upgrade this working code:
Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
Dim Ns As Outlook.NameSpace

Set Ns = Application.GetNamespace("MAPI")
Set Items = Ns.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If TypeOf Item Is Outlook.MailItem Then
PrintNewItem Item
End If
End Sub

Private Sub PrintNewItem(Mail As Outlook.MailItem)
On Error Resume Next

If MsgBox("Print?", vbYesNo Or vbQuestion) = vbYes Then
Mail.PrintOut
End If

End Sub

replacement code that dosn't work:


Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
Dim Ns As Outlook.NameSpace

Set Ns = Application.GetNamespace("MAPI")
Set Items = Ns.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If TypeOf Item Is Outlook.MailItem Then
PrintNewItem Item
End If
End Sub

Private Sub PrintNewItem(Mail As Outlook.MailItem)
Dim sPrinter As String
On Error Resume Next

If MsgBox("Print?", vbYesNo Or vbQuestion) = vbYes Then
Mail.PrintOut
With Dialogs(wdDialogFilePrintSetup)
sPrinter = .Printer
.Printer = "HP LaserJet 4050 Series PS"
.DoNotSetAsSysDefault = True
.Execute
Dialogs(wdDialogFilePrint).Show
.Printer = sPrinter
.DoNotSetAsSysDefault = True
.Execute
End With

End Sub

End If

End Sub

ANY FOOL CAN DESIGN A STRUCTURE. IT TAKES AN ENGINEER TO DESIGN A CONNECTION.”
 
Replies continue below

Recommended for you

Try moving the Mail.PrintOut statement after the 'with' block that changes the settings.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor