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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to print to MDI From Outlook

Status
Not open for further replies.

imarg

Technical User
Jun 5, 2006
18
CA
Hi everyone,

I am trying to build an outlook macro that will take a selected message and print it to a specific Microsoft Office Document Image Writer file on a users computer

I have gotten as far getting the default printer changed to image writer, and to printout.

The problem is that I want it to print to an MDI file to a location that I want it to go to (without the saveas dialogue box popping up). Help would be very much appreciated. Thanks

My Code is below:

Sub printToMDI()
On Error Resume Next
Dim strOldDefault
Set objFSO = CreateObject("Scripting.FileSystemObject")


Dim myItem As Outlook.Inspector
Dim objItem As Object
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.ActiveInspector
If Not TypeName(myItem) = "Nothing" Then
Set objItem = myItem.CurrentItem
strname = objItem.Subject
MsgBox strname
'Prompt the user for confirmation
Dim strPrompt As String
strPrompt = "Are you sure you want to Print."
If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then

strOldDefault = fnMDIPrint

objItem.PrintOut FileName:="C:\test.mdi"
If Err > 0 Then
MsgBox Err.Description
Err = 0
End If
Call setDefPrint(strOldDefault)
End If
Else
MsgBox "There is no current active inspector."
End If
End Sub

Function fnMDIPrint()
Dim strComputer
Dim objWMIService
Dim colPrinters
Dim strOldDefault
Dim objPrinter
Dim Temp, i

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Default = TRUE")

For Each objPrinter In colPrinters
strOldDefault = objPrinter.Name
strOldDefault = Replace(strOldDefault, "\", "\\")
Next

Set colPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Name = 'Microsoft Office Document Image Writer'")

For Each objPrinter In colPrinters
Temp = objPrinter.SetDefaultPrinter()
Next

For i = 0 To i = 2000
i = i + 1
Next
fnMDIPrint = strOldDefault
End Function
Sub setDefPrint(strOldDefault)
Dim strComputer
Dim objWMIService
Dim colPrinters
Dim objPrinter
Dim Temp
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where Name = '" & strOldDefault & "'")

For Each objPrinter In colPrinters
Temp = objPrinter.SetDefaultPrinter()
Next
End Sub




Thanks, IMarg

 
One More Thing...
The objItem.PrintOut FileName:="C:\test.mdi" portion of the code is the problem.

objItem.PrintOut works by itself but produces a dialogue box, the FileName portion of it creates an error
"Named Argument Not Found"

Thanks Imarg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top