×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

outllook script/vba

outllook script/vba

outllook script/vba

(OP)
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."
 

RE: outllook script/vba

Try moving the Mail.PrintOut statement after the 'with' block that changes the settings.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources