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