Hi,
I would like to make a routine in Excel (2003), from which I look in a group-mailbox and if the mail subject begins with eg "ABC D" I will print it on a special printer.
My problem is, that using Application.ActivePrinter to change the printer works if I am printing from Excel, but now I am printing from Outlook, and default printer is not changed.
My code is:
Private Sub PrintOutlookMail()
Dim objApp As Object
Dim objNs As Namespace
Dim objFolder As MAPIfolder
Dim objItem As MailItem
Dim oldprinter As String
Set objApp = CreateObject("Outlook.application")
Set objNs = objApp.GetNameSpace("MAPI")
oldprinter = Application.ActivePrinter
Application.ActivePrinter = "\\dicph-srv-fs01\DDS_A4_Print1 på Ne09:"
Set objFolder = objNs.Folders("qwerr@qwer.com").Folders("Inbox")
If objFolder.Items.Count = 0 Then
MsgBox "No mails to print"
Else
For Each objItem In objFolder.Items
If Left(objItem.Subject, 5) = "ABC D" Then
objItem.PrintOut
objItem.Move (objNs.Folders("qwerr@qwer.com").Folders("Done"))
End If
Next
End If
Application.ActivePrinter = oldprinter
End Sub
-----------------
How can I control the Outlook printer?
Janne
I would like to make a routine in Excel (2003), from which I look in a group-mailbox and if the mail subject begins with eg "ABC D" I will print it on a special printer.
My problem is, that using Application.ActivePrinter to change the printer works if I am printing from Excel, but now I am printing from Outlook, and default printer is not changed.
My code is:
Private Sub PrintOutlookMail()
Dim objApp As Object
Dim objNs As Namespace
Dim objFolder As MAPIfolder
Dim objItem As MailItem
Dim oldprinter As String
Set objApp = CreateObject("Outlook.application")
Set objNs = objApp.GetNameSpace("MAPI")
oldprinter = Application.ActivePrinter
Application.ActivePrinter = "\\dicph-srv-fs01\DDS_A4_Print1 på Ne09:"
Set objFolder = objNs.Folders("qwerr@qwer.com").Folders("Inbox")
If objFolder.Items.Count = 0 Then
MsgBox "No mails to print"
Else
For Each objItem In objFolder.Items
If Left(objItem.Subject, 5) = "ABC D" Then
objItem.PrintOut
objItem.Move (objNs.Folders("qwerr@qwer.com").Folders("Done"))
End If
Next
End If
Application.ActivePrinter = oldprinter
End Sub
-----------------
How can I control the Outlook printer?
Janne