Save and Print attachments
Hello,
I have a question. I am trying to extend the rules of Outlook. There will be emails coming in from many, many people, all with the same subject line. I want to flag all of these that come in and put them into a folder of their own. This is done currently into an Outlook folder.
What I want to do now is to save the attachment (as all will have the attachment) to a specific folder. I would then like to print a copy of this attachment. I know exactly what is in the file, it is a returned form and will only take one sheet to print on. The attachment is an Excel file.
Can this be done? And can it be run automatically from whence the mail comes in? Thanks for your help! :yes
Save Attachments Outlook 2000
I receive excel sheets as attachments which I then review respond then save them. I also used the rule wizard to put the new messaqges in a folder. I highlight the folder once a week and run the code. I wrote the code below to check the attachments file names and put them in the proper folder on the hard drive. The form (CurAtchmntStatusFrm) shows the status as the files are being saved and notifes me of files that are out of the norm. I review then select all and delete. The code is rough I don't program for a living more of a hobby but, I think it can be adapted for your use I haven't cleaned it up so it's as is. Path sPathName = "C:\Documents and Settings\YourFolder\My Documents\XL\Hrs\ well have to be a valid folder. Hope this helps :friends:
[VBA]
Option Base 1
Public Sub CleanOutOlFldAthmntsMain()
Static CurOlMsgsAtchmntCnt As Integer
Dim VarArry()
CurYear = Year(Date)
iAttachCntTot = 0
icnt = 0
'ArryCntr = 0
'Code Below Same as In UserForm
Set oCurFldrSlctd = Outlook.ActiveExplorer.Selection.Parent.CurrentFolder 'Outlook Current Folder Selected
Set OlMsgObj = oCurFldrSlctd.Items 'Outlook Current Selected Folder All Message Items
OlMsgCnt = OlMsgObj.Count 'Count of Outlook Current Selected Folder All Message Items
'Get File Info:
For MsgCntr = 1 To OlMsgCnt
LoopCtnr = 0
Set OlMsgObjI = OlMsgObj.Item(MsgCntr) 'Message item number in folder
Set OlMsgObjIAtchmts = OlMsgObjI.Attachments 'All Current Attachments in message
CurOlMsgsAtchmntCnt = OlMsgObjI.Attachments.Count ' Count of All Attachments in current message
For CurOlMsgsAtchmntCntr = 1 To CurOlMsgsAtchmntCnt
sPathNameLbl = ""
OpType = ""
LoopCtnr = LoopCtnr + 1
If LoopCtnr > CurOlMsgsAtchmntCnt Then
Exit For
End If
Set CurOlMsgAtchmnt = OlMsgObjIAtchmts.Item(CurOlMsgsAtchmntCntr)
CurStatus = ""
SavToHolidyFldr = ""
'Chk If File is Elect.Xls:
If Not CurOlMsgAtchmnt Like "*elec*" Then
GoTo NonEltFlTyp
End If
HldyChkNam = Array("*Day*", "*Christmas*", "*4TH*", "*MLK*", "*THANKSGIVING*", "*MEM*", "*EASTER*")
icnt = 0
For Each XItem In HldyChkNam
icnt = icnt + 1
Next XItem
For HldyChk = 1 To icnt
If CurOlMsgAtchmnt Like "*" & HldyChkNam(HldyChk) & "*" Then
SavToHolidyFldr = "Holiday\"
Exit For
End If
Next HldyChk
If CurOlMsgAtchmnt Like "*charge*" Then
SavToPathFldr = "charges\"
ElseIf CurOlMsgAtchmnt Like "*newhour*" Then
SavToPathFldr = "Newhours\"
ElseIf CurOlMsgAtchmnt Like "*asking*" Then
SavToPathFldr = "Asking\"
ElseIf CurOlMsgAtchmnt Like "*Assign*" Then
SavToPathFldr = "Assignments\"
Else
SavToPathFldr = "Assignments\"
End If
sPathName = "C:\Documents and Settings\YourFolder\My Documents\XL\Hrs\" & SavToPathFldr & SavToHolidyFldr 'My Folder Path where to save attachments
sPathNameLbl = "C:\My Documents\XL\Hrs\" & SavToPathFldr & SavToHolidyFldr 'My Folder Path where to save attachments
CurStatus = "Is Being Saved To"
OpType = "SaveAsFile"
AtthmtsSavdQty = AtthmtsSavdQty + 1
GoTo IsEltFlTyp
NonEltFlTyp:
If CurOlMsgAtchmnt Like "*carp*" Then
'iCtr = iCtr - 1
AtthmtsDeldQty = AtthmtsDeldQty + 1
CurStatus = "Deleting File"
OpType = "Delete"
ElseIf CurOlMsgAtchmnt Like "*comm*" Then
'iCtr = iCtr - 1
AtthmtsDeldQty = AtthmtsDeldQty + 1
CurStatus = "Delete"
OpType = "Delete"
Else
OpType = "No Action"
End If
IsEltFlTyp:
iLoopCnt = iLoopCnt + 1
'Pass Variables to UserForm
Load CurAtchmntStatusFrm
CurAtchmntStatusFrm.sPathName = sPathName
CurAtchmntStatusFrm.FileName = CurOlMsgAtchmnt
CurAtchmntStatusFrm.OpType = OpType 'Operation top perform Delete / SaveAs
CurAtchmntStatusFrm.MsgCntr = MsgCntr
CurAtchmntStatusFrm.CurOlMsgsAtchmntCntr = CurOlMsgsAtchmntCntr
CurAtchmntStatusFrm.CurOlMsgsAtchmntCnt = CurOlMsgsAtchmntCnt
CurAtchmntStatusFrm.Caption = oCurFldrSlctd & " Outlook Folder"
CurAtchmntStatusFrm.CurAthmtFlNam.Caption = CurOlMsgAtchmnt
CurAtchmntStatusFrm.CurStatusLbl.Caption = CurStatus
CurAtchmntStatusFrm.CurFileSavPathLbl.Caption = sPathNameLbl
If OpType = "Delete" Then
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Do you really want to Delete " & CurOlMsgAtchmnt ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "ARE YOU SURE" ' Define title.
' Display message.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
OpType = "Delete" ' Perform some action.
CurOlMsgsAtchmntCntr = CurOlMsgsAtchmntCntr - 1
'OlMsgObjI.Display
Else ' User chose No.
OpType = "No Action"
Exit For
End If
'MsgBox ("Do you really want to Delete! " & FileName)
End If
CurAtchmntStatusFrm.StartUpPosition = 1
CurAtchmntStatusFrm.Show
Next CurOlMsgsAtchmntCntr
Next MsgCntr
GoTo EndIt
NoCanDo:
If iAttachCntTot = 0 Then
MsgBox (" NO ATTACHMENTS FOUND ")
Else
'Dim Msg, Style, Title, Response, MyString
Title = iAttachCntTot & " ATTACHMENTS FOUND and " & AtthmtsSavdQty & " Backed up to Hard Drive Folder" ' Define title.
Msg = "Do you want to Delete Messages in " & oCurFldrSlctd & " Folder?" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
' Display message.
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
MyString = "Yes" ' Perform action.
Else ' User chose No.
MyString = "No" ' Perform action.
End If
End If
EndIt:
Unload CurAtchmntStatusFrm
End Sub
[/VBA]