Hi,
I have used a script off the web to save attachments in my g drive and also print the attachment. Works great as a script rule.
I've tried to replicate this script copying into a diff module and renaming the sub, only difference is the folder path where I'm saving the attachment. Running it again as a script rule however, I get an error message script doesn't exist or is invalid.
I've deleted and re-inserted the module & renamed the sub to no avail. Tried removing the move to folder step in the rule before run a script step.
;Orig script
Edited script:
Any help much appreciated.
I have used a script off the web to save attachments in my g drive and also print the attachment. Works great as a script rule.
I've tried to replicate this script copying into a diff module and renaming the sub, only difference is the folder path where I'm saving the attachment. Running it again as a script rule however, I get an error message script doesn't exist or is invalid.
I've deleted and re-inserted the module & renamed the sub to no avail. Tried removing the move to folder step in the rule before run a script step.
;Orig script
Code:
Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Sub PrintAttachments(oMail As Outlook.MailItem)
Dim colAtts As Outlook.Attachments
Dim oAtt As Outlook.Attachment
Dim sFile As String
Dim sDirectory As String
Dim sFileType As String
sDirectory = "G:\My Drive\Outlook attachments\End of Day\Sage\"
Set colAtts = oMail.Attachments
If colAtts.Count Then
For Each oAtt In colAtts
' This code looks at the last 4 characters in a filename
sFileType = LCase$(Right$(oAtt.FileName, 4))
Select Case sFileType
' Add additional file types below
Case ".pdf", ".doc", "docx"
sFile = sDirectory & oAtt.FileName
oAtt.SaveAsFile sFile
ShellExecute 0, "print", sFile, vbNullString, vbNullString, 0
End Select
Next
End If
End Sub
Edited script:
Code:
Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Sub Picko(oMail As Outlook.MailItem)
Dim colAtts As Outlook.Attachments
Dim oAtt As Outlook.Attachment
Dim sFile As String
Dim sDirectory As String
Dim sFileType As String
sDirectory = "G:\My Drive\Outlook attachments\Picking Notes\"
Set colAtts = oMail.Attachments
If colAtts.Count Then
For Each oAtt In colAtts
' This code looks at the last 4 characters in a filename
sFileType = LCase$(Right$(oAtt.FileName, 4))
Select Case sFileType
' Add additional file types below
Case ".pdf", ".doc", "docx"
sFile = sDirectory & oAtt.FileName
oAtt.SaveAsFile sFile
ShellExecute 0, "print", sFile, vbNullString, vbNullString, 0
End Select
Next
End If
End Sub
Any help much appreciated.