PDA

View Full Version : Solved: Standard ReplyAll with an attachment



wagnet
01-17-2006, 09:39 AM
I'm an Outlook 2003 VBA newbie trying to write a macro that will ReplyAll to the current (Inspector) email, add an attachment (C:Form.doc), and add text ("Please complete the attached form and return to sender.") to the top of the Body.

I have made several attempts, but each results in various errors (e.g. standard Reply format is altered (as set by: Outlook / Tools / Options / Preferences / E-mail Options / On Replies and Forwards / Include original message text).

Does anyone have a ReplyAll macro (that includes an .Add attachment) that I can use as a reference? Thanks, signed Newbie :banghead:

wagnet
01-17-2006, 03:48 PM
I finally got it to work. Let me know if you see any code improvements that can be made. Thanks.

Sub Reply2AllSCQ()

' 2006 January 17 AAW - Written
' ReplyAll to open email requesting sender complete and return the attached SQC file
Dim objOutlook As Outlook.Application
Dim atts As Outlook.Attachments
Dim newAttachement As Outlook.Attachments
Dim objMail As Outlook.MailItem
Dim objItem As Object
Dim strAddress As String
Dim strName As String
Dim strEntryID As String
Dim strMessage As String

strMessage = "Please complete and return the attached SCQ Form." & vbCrLf & vbCrLf & "Thank You."
Set objOutlook = CreateObject("Outlook.Application")
Set objItem = objOutlook.ActiveInspector.CurrentItem
Set objMail = objItem.ReplyAll

CopyBody = objMail.Body
objMail.Body = vbCrLf & strMessage & vbCrLf & vbCrLf & CopyBody
Set newAttachments = objMail.Attachments
newAttachments.Add "C:SCQ.doc", _
olByValue, 1, "SCQ Questionnaire"
objMail.Display

End Sub

mdmackillop
01-17-2006, 04:54 PM
Hi Wagnet,
Welcome to VBAX.
I'm sure some Outlook knowlegeable person will be along soon. When you post code, if you select it and click the VBA burtton, it will format your code making it more readable. Please also use linebreaks in long lines of code, to avoid the need for scrolling.
Regards MD