![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
Hi,
Let me preface this with that I am at the limit of my knowledge making the few edits I have to a great script I found elsewhere. The script copies attachments out of emails into a folder. I have added the function of giving each file attachment a unique name. It then replaces the attachments with a link to the new filename. It will not work because the item needs to be highlighted while it is running for some reason. Outlook does not highlight new items as they arrive / leave so it works manually, but will not work as a rule. Help greatly appreciated. Here it is. Public Sub SaveAttachments(objMailItem As MailItem) Dim objOL As Outlook.Application Dim objMsg As Outlook.MailItem 'Object Dim objAttachments As Outlook.Attachments Dim objSelection As Outlook.Selection Dim i As Long Dim lngCount As Long Dim strFile As String Dim strFolderpath As String Dim strDeletedFiles As String Dim strFileExt As String ' Set the path to documents folder strFolderpath = "c:\HomeDrive" On Error Resume Next ' Instantiate an Outlook Application object. Set objOL = CreateObject("Outlook.Application") ' Get the collection of selected objects. Set objSelection = objOL.ActiveExplorer.Selection ' Set the Attachment folder. strFolderpath = strFolderpath & "\OLAttachments\" 'MsgBox strFolderpath ' Check each selected item for attachments. ' If attachments exist, save them to the Temp ' folder and strip them from the item. For Each objMsg In objSelection ' This code only strips attachments from mail items. ' If objMsg.class=olMail Then ' Get the Attachments collection of the item. Set objAttachments = objMsg.Attachments lngCount = objAttachments.Count 'MsgBox objAttachments.Count If lngCount 0 Then ' We need to use a count down loop for ' removing items from a collection. Otherwise, ' the loop counter gets confused and only every ' other item is removed. For i = lngCount To 1 Step -1 ' Save attachment before deleting from item. ' Get the file name. strFile = objAttachments.Item(i).FileName ' Get the file extension strFileExt = Right(strFile, 3) ' Get the EntryID strFile = objMsg.EntryID ' Replace Filename with MessageID and index number + file extension strFile = strFile & i & "." & strFileExt ' Combine with the path to the Temp folder. strFile = strFolderpath & strFile ' Save the attachment as a file. objAttachments.Item(i).SaveAsFile strFile ' Delete the attachment. objAttachments.Item(i).Delete 'write the save as path to a string to add to the message 'check for html and use html tags in link If objMsg.BodyFormat olFormatHTML Then strDeletedFiles = strDeletedFiles & vbCrLf & "file://" & strFile & "" Else strDeletedFiles = strDeletedFiles & "br" & "a href='file://" & _ strFile & "'" & strFile & "/a" End If 'MsgBox strDeletedFiles Next i ' End If ' Adds the filename string to the message body and save it ' Check for HTML body If objMsg.BodyFormat olFormatHTML Then objMsg.Body = objMsg.Body & vbCrLf & _ "The file(s) were saved to " & strDeletedFiles Else objMsg.HTMLBody = objMsg.HTMLBody & "p" & _ "The file(s) were saved to " & strDeletedFiles End If objMsg.Subject = objMsg.Subject & "ATTACHMENT/S" objMsg.Save End If Next ExitSub: Set objAttachments = Nothing Set objMsg = Nothing Set objSelection = Nothing Set objOL = Nothing End Sub Thanks in advance. Andrew |
Ads |
#2
|
|||
|
|||
![]()
Your code has a major redundancy: The item that triggered the rule is the objMailItem object passed as an argument. Yet you are instantiating an Outlook.Application object (totally unnecessary) and a Selection object. Instead, your code needs to act on the item that fired the rule.
-- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Andrew" wrote in message ... Hi, Let me preface this with that I am at the limit of my knowledge making the few edits I have to a great script I found elsewhere. The script copies attachments out of emails into a folder. I have added the function of giving each file attachment a unique name. It then replaces the attachments with a link to the new filename. It will not work because the item needs to be highlighted while it is running for some reason. Outlook does not highlight new items as they arrive / leave so it works manually, but will not work as a rule. Help greatly appreciated. Here it is. Public Sub SaveAttachments(objMailItem As MailItem) Dim objOL As Outlook.Application Dim objMsg As Outlook.MailItem 'Object Dim objAttachments As Outlook.Attachments Dim objSelection As Outlook.Selection Dim i As Long Dim lngCount As Long Dim strFile As String Dim strFolderpath As String Dim strDeletedFiles As String Dim strFileExt As String ' Set the path to documents folder strFolderpath = "c:\HomeDrive" On Error Resume Next ' Instantiate an Outlook Application object. Set objOL = CreateObject("Outlook.Application") ' Get the collection of selected objects. Set objSelection = objOL.ActiveExplorer.Selection ' Set the Attachment folder. strFolderpath = strFolderpath & "\OLAttachments\" 'MsgBox strFolderpath ' Check each selected item for attachments. ' If attachments exist, save them to the Temp ' folder and strip them from the item. For Each objMsg In objSelection ' This code only strips attachments from mail items. |
#3
|
|||
|
|||
![]()
Thanks Sue ... apprecite you time.
Better pull your book off the shelf again :-) Andrew "Sue Mosher [MVP-Outlook]" wrote: Your code has a major redundancy: The item that triggered the rule is the objMailItem object passed as an argument. Yet you are instantiating an Outlook.Application object (totally unnecessary) and a Selection object. Instead, your code needs to act on the item that fired the rule. -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Andrew" wrote in message ... Hi, Let me preface this with that I am at the limit of my knowledge making the few edits I have to a great script I found elsewhere. The script copies attachments out of emails into a folder. I have added the function of giving each file attachment a unique name. It then replaces the attachments with a link to the new filename. It will not work because the item needs to be highlighted while it is running for some reason. Outlook does not highlight new items as they arrive / leave so it works manually, but will not work as a rule. Help greatly appreciated. Here it is. Public Sub SaveAttachments(objMailItem As MailItem) Dim objOL As Outlook.Application Dim objMsg As Outlook.MailItem 'Object Dim objAttachments As Outlook.Attachments Dim objSelection As Outlook.Selection Dim i As Long Dim lngCount As Long Dim strFile As String Dim strFolderpath As String Dim strDeletedFiles As String Dim strFileExt As String ' Set the path to documents folder strFolderpath = "c:\HomeDrive" On Error Resume Next ' Instantiate an Outlook Application object. Set objOL = CreateObject("Outlook.Application") ' Get the collection of selected objects. Set objSelection = objOL.ActiveExplorer.Selection ' Set the Attachment folder. strFolderpath = strFolderpath & "\OLAttachments\" 'MsgBox strFolderpath ' Check each selected item for attachments. ' If attachments exist, save them to the Temp ' folder and strip them from the item. For Each objMsg In objSelection ' This code only strips attachments from mail items. |
#4
|
|||
|
|||
![]()
It was really impossible to find something like this... after searching
for over an hour , I muddled through and modified the "select and save macro from somewhere" to do what I wanted. It will automatically save any attachments on incoming new emails to C:\Attachments It probably has some flaws that could be fixed or w/e, but it does what I want. Sub SaveAttachments(Item As Outlook.MailItem) Dim i As Long Dim lngCount As Long Dim strFile As String Dim strFolderpath As String strFolderpath = "C:\Attachments\" On Error Resume Next Set objAttachments = Item.Attachments lngCount = objAttachments.Count If lngCount 0 Then For i = lngCount To 1 Step -1 strFile = objAttachments.Item(i).FileName strFile = strFolderpath & strFile objAttachments.Item(i).SaveAsFile strFile Next i End If ExitSub: Set objAttachments = Nothing End Sub Andrew wrote: Thanks Sue ... apprecite you time. Better pull your book off the shelf again :-) Andrew "Sue Mosher [MVP-Outlook]" wrote: Your code has a major redundancy: The item that triggered the rule is the objMailItem object passed as an argument. Yet you are instantiating an Outlook.Application object (totally unnecessary) and a Selection object. Instead, your code needs to act on the item that fired the rule. -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Andrew" wrote in message ... Hi, Let me preface this with that I am at the limit of my knowledge making the few edits I have to a great script I found elsewhere. The script copies attachments out of emails into a folder. I have added the function of giving each file attachment a unique name. It then replaces the attachments with a link to the new filename. It will not work because the item needs to be highlighted while it is running for some reason. Outlook does not highlight new items as they arrive / leave so it works manually, but will not work as a rule. Help greatly appreciated. Here it is. Public Sub SaveAttachments(objMailItem As MailItem) Dim objOL As Outlook.Application Dim objMsg As Outlook.MailItem 'Object Dim objAttachments As Outlook.Attachments Dim objSelection As Outlook.Selection Dim i As Long Dim lngCount As Long Dim strFile As String Dim strFolderpath As String Dim strDeletedFiles As String Dim strFileExt As String ' Set the path to documents folder strFolderpath = "c:\HomeDrive" On Error Resume Next ' Instantiate an Outlook Application object. Set objOL = CreateObject("Outlook.Application") ' Get the collection of selected objects. Set objSelection = objOL.ActiveExplorer.Selection ' Set the Attachment folder. strFolderpath = strFolderpath & "\OLAttachments\" 'MsgBox strFolderpath ' Check each selected item for attachments. ' If attachments exist, save them to the Temp ' folder and strip them from the item. For Each objMsg In objSelection ' This code only strips attachments from mail items. |
#5
|
|||
|
|||
![]()
Sue -- or anyone else: is there really no way to create rules and alerts,
change their parameters, or even examine them in code? There's no way to enumerate the rules and dump all their parameters to a text file, for example? Is it really all hidden away? How then is the Rules Wizard implemented? -- Andy Smith Senior Systems Analyst Standard & Poor''s, NYC "Sue Mosher [MVP-Outlook]" wrote: Your code has a major redundancy: The item that triggered the rule is the objMailItem object passed as an argument. Yet you are instantiating an Outlook.Application object (totally unnecessary) and a Selection object. Instead, your code needs to act on the item that fired the rule. -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Andrew" wrote in message ... Hi, Let me preface this with that I am at the limit of my knowledge making the few edits I have to a great script I found elsewhere. The script copies attachments out of emails into a folder. I have added the function of giving each file attachment a unique name. It then replaces the attachments with a link to the new filename. It will not work because the item needs to be highlighted while it is running for some reason. Outlook does not highlight new items as they arrive / leave so it works manually, but will not work as a rule. Help greatly appreciated. Here it is. Public Sub SaveAttachments(objMailItem As MailItem) Dim objOL As Outlook.Application Dim objMsg As Outlook.MailItem 'Object Dim objAttachments As Outlook.Attachments Dim objSelection As Outlook.Selection Dim i As Long Dim lngCount As Long Dim strFile As String Dim strFolderpath As String Dim strDeletedFiles As String Dim strFileExt As String ' Set the path to documents folder strFolderpath = "c:\HomeDrive" On Error Resume Next ' Instantiate an Outlook Application object. Set objOL = CreateObject("Outlook.Application") ' Get the collection of selected objects. Set objSelection = objOL.ActiveExplorer.Selection ' Set the Attachment folder. strFolderpath = strFolderpath & "\OLAttachments\" 'MsgBox strFolderpath ' Check each selected item for attachments. ' If attachments exist, save them to the Temp ' folder and strip them from the item. For Each objMsg In objSelection ' This code only strips attachments from mail items. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Rules & Alerts Outlook 2003 | Vidya | Outlook - General Queries | 2 | September 8th 06 03:46 PM |
rules and alerts limits with outlook 2003 & Exchange 2003 | Jeje | Outlook - General Queries | 2 | June 9th 06 01:44 AM |
Outlook 2003 Rules & Alerts | SAlders | Outlook - General Queries | 0 | May 30th 06 07:22 PM |
In Outlook 2003 I can't get the 'run now' to work in 'rules&Alerts | marigold247 | Outlook - General Queries | 3 | April 4th 06 05:46 PM |
Outlook 2003 Rules and Alerts Organiser | Ian Mitchell | Outlook - General Queries | 2 | January 31st 06 12:24 AM |