| Code level: intermediate Code area: Basic Outlook Printer Friendly Version | ||
| Title: Reply with Attachments | ||
| Description: This Outlook VBA sample creates and displays a reply to the currently open or selected message including the attachments in the original. | ||
| Date: 07-Apr-2006 13:17 | ||
| Code level: intermediate | ||
| Code area: Basic Outlook | ||
| Posted by: Sue Mosher | ||
This message is displayed as VB.NET
Sub ReplyWithAttachments()
Dim rpl As Outlook.MailItem
Dim itm As Object
Set itm = GetCurrentItem()
If Not itm Is Nothing Then
Set rpl = itm.Reply
CopyAttachments itm, rpl
rpl.Display
End If
Set rpl = Nothing
Set itm = Nothing
End Sub
Function GetCurrentItem() As Object
Dim objApp As Outlook.Application
Set objApp = Application
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
End Select
Set objApp = Nothing
End Function
Sub CopyAttachments(objSourceItem, objTargetItem)
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldTemp = fso.GetSpecialFolder(2) ' TemporaryFolder
strPath = fldTemp.Path & "\"
For Each objAtt In objSourceItem.Attachments
strFile = strPath & objAtt.FileName
objAtt.SaveAsFile strFile
objTargetItem.Attachments.Add strFile, , , objAtt.DisplayName
fso.DeleteFile strFile
Next
Set fldTemp = Nothing
Set fso = Nothing
End Sub
|
||
| All 135comments |
| Page [ 1 2 3 4 5 6 7 8 9 10 Next >> ] | ||
|
|
Sue Mosher
07-Apr-2006 13:19
Notes on the code: 1) Uses the GetCurrentItem() function from http://www.outlookcode.com/codedetail.aspx?id=50 to return the currently selected or displayed item. 2) Uses the CopyAttachments() procedure from http://www.outlookcode.com/d/code/copyatts.htm to copy the attachments to the reply. 3) Replace itm.Reply with itm.ReplyAll if you prefer to reply to all. |
|
|
|
Anonymous
07-Apr-2006 18:11
Most excellent, Thank you... |
|
|
|
Jai Rao
06-Jun-2006 22:23
Hail to Sue Mosher - this is a big time & pain saver |
|
|
|
Flash
15-Jun-2006 13:14
OMG, this rocks! I have been looking everywhere for something like this! Thank you! Thank you! Thank you! |
|
|
|
Leah Ann
25-Jul-2006 11:29
This is great! One little annoyance, though...Is there any way to keep it from copying the background image as an attachment as well? |
|
|
|
Sue Mosher
25-Jul-2006 12:12
Leah Ann, the easy solution would be to check the file extension and not copy any images. |
|
|
|
Chelsi
25-Jul-2006 15:01
This is fabulous! Our users will be thrilled! However, this doesn't seem to work on "reply to all". Should it? |
|
|
|
Sue Mosher
25-Jul-2006 16:31
Chelsi, look at the code. The statement that creates the reply is: Set rpl = itm.Reply You could certainly change it to ReplyAll if you wanted to. |
|
|
|
Chelsi
27-Jul-2006 09:06
You're very kind to share your tips with us! Thank you! |
|
|
|
Alex
15-Aug-2006 05:06
Can't thank-you enough, the code works a treat ! |
|
| Page [ 1 2 3 4 5 6 7 8 9 10 Next >> ] | ||
| Post your comment name email |
