Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

How do I control Outlook printer from Excel

Status
Not open for further replies.

jaol

Programmer
Oct 16, 2003
13
DK
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
 



hi,
You are running this code in Excel VBA. Correct?
Code:
Set objApp = CreateObject("Outlook.application")
Set objNs = objApp.GetNameSpace("MAPI")

oldprinter = [b][red]Application[/red][/b].ActivePrinter
[b][red]Application[/red][/b].ActivePrinter = "\\dicph-srv-fs01\DDS_A4_Print1 på Ne09:"
[red]Application[/red] is the Excel Application Object.

Why are you not using the Outlook Application Object?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Yes I am running it from Excel VBA.

I have a kind of central Excel application which is used by a lot of people. And I would like to give them all the possibility to print these outlook mails without going through outlook and change the printer.

(And then, I have very little knowledge about Outlook, its structure and objects. :)
 



Actually, I cannot find a reference in Outlook for a printer. Outlook is a strange animal. Not many prople have a good grasp of the object model.

I'll keep looking as I am able.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top