Private Declare Function ShellExecuteA Lib "Shell32" (ByVal hwnd As Integer, ByVal lpOperation As String, ByVal lpFile As String, lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Integer) As Integer
Sub CustomMailMessageRule(Item As Outlook.MailItem)
'******** Written 07/28/2005
'******** This Outlook script will fax an email attachment to the phone # in the subject line
'******** This code is provided As-Is with no warranty expressed or implied.
If Item.Attachments.Count = 0 Then Exit Sub ' stop if there are no attachments
Dim sPath As String
sPath = "C:\faxtemp\" + Item.Attachments.Item(1).FileName
Item.Attachments.Item(1).SaveAsFile (sPath) 'save attachment to C:\faxtemp
Dim RetVal
RetVal = ShellExecuteA(0, "print", """" + sPath + """", vbNullString, vbNullString, 0)
'******** Wait for 10 seconds so the Fax Wizard dialog has time to appear ********'
PauseTime = 10 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
Finish = Timer
SendKeys "{ENTER}", True 'Press ENTER to go to next screen on Fax Wizard
PauseTime = 2
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop
Finish = Timer
SendKeys Right$(Item.Subject, 10), True 'Enter last 10 characters of subject as recipient
SendKeys "{TAB}" & "{TAB}", True 'Press TAB to skip to the correct box on dialog
SendKeys Right$(Item.Subject, 10), True 'Enter last 10 characters of subject as phone
PauseTime = 1
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop
Finish = Timer
SendKeys "{ENTER}", True 'Press ENTER to go to next screen
PauseTime = 1
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop
Finish = Timer
SendKeys "{ENTER}", True 'Press ENTER to go to next screen
PauseTime = 1
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop
Finish = Timer
SendKeys "{ENTER}", True 'Press ENTER to go to next screen
PauseTime = 1
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop
Finish = Timer
SendKeys "{ENTER}", True 'Press ENTER to Finish
End Sub
|