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