Automatic reply on incoming messages in outlook using VBA(only Specifi person)

Status
Not open for further replies.

pbpver1

Member
Outlook version
Email Account
Exchange Server
Hi,

im very new to VBA coding and forum. autucally im looking for to automatic reply on same email to particular person when they send to inbox.


For example:

If subject of incoming message particular person/recipient. i need automatic reply on that message with text in the body "xxxxx" rply on same email.
 
Re: Automatic reply on incoming messages in outlook using VBA(only Specifi per

You'd use a run a script rule - the rule looks for the conditions then passes it off to the script.

Start with http://www.slipstick.com/outlook/rules/run-script-rule-change-subject-message/

and change it to something like this -

Set myForward = Item.Reply

myforward.body = "new text" & myforward.body

myForward.Send

If you are using word as the editor, you can use some word commands to insert text at the top.

Dim olInspector As Outlook.Inspector
Dim olDocument As Word.Document
Dim olSelection As Word.Selection

olSelection.InsertBefore "your text"

(I'll write up a proper macro that word.selection and put it on slipstick.)
 
Re: Automatic reply on incoming messages in outlook using VBA(only Specifi per

Really im very sorry. as im very new VBA. i didnt get you. could you explain inmore deatil.

hope you can understand me.
 
Hi and HELP!!
This VBA automatic reply is driving me nuts. It sort of worked occasionally but as I fiddled my way towards the desired goal it stopped working and now I cant get it to work at all (well the rule works but the script is never run) so:
I deleted the VBA module1 and the rule; Shut down and reopened outlook and started again and then:
1. Create VBA macro and copy/paste the code at http://www.slipstick.com/outlook/rules/run-script-rule-reply-message/
2. Edit the address of the oft file to point to my oft file.
3. Add the mail rule (specific words in senders address) + stop processing more rules
4 Send email to check the rule conditions (by making the action something obvious - move message to another folder) - it works!
5 Change rule action to run script (remove the move to folder part)
6 Resend email from step 4
7 Macro does not execute (.display does not display message)
8 Add action to move message to the rule
9 Resend email from step 4
10 Macro does not execute but email is moved.
11 Tear hair out!

So what am I doing wrong?

Also, it seems when it was working that the email was sent directly rather than put in the outbox? Is this the case? Is there anyway to getthe reply put in the outbox in the normal way?

Thanks for any suggestions

The macro is
Sub AutoReplywithTemplate(Item As Outlook.MailItem)
Dim oRespond As Outlook.MailItem

' Use this for a real reply
' Set oRespond = Item.Reply

' This sends a response back using a template
Set oRespond = Application.CreateItemFromTemplate("D:\Data\mail\MS-Receipt.oft")

With oRespond
.Recipients.Add Item.SenderEmailAddress
.Subject = "Your Subject Goes Here"
.HTMLBody = "Your reply text goes here." & vbCrLf & _
"---- original body below ---" & vbCrLf & _
Item.HTMLBody & vbCrLf & _
"---- Template body below ---" & _
vbCrLf & oRespond.HTMLBody

' includes the original message as an attachment
.Attachments.Add Item

' use this for testing, change to .send once you have it working as desired
.Display
End With
Set oRespond = Nothing
End Sub
 
3. Add the mail rule (specific words in senders address) + stop processing more rules

I'm not sure if its the cause of your problems, but you should only use conditions in the rule, not actions. The script handles all actions.

Everything else looks fine - it should work as long as the path to the template is correct.
 
Thanks for the reply.
Yes well I thought everything looked fine as well :-( hence the absence of hair!
What else can I do/try to get to the bottom of this?

1. http://www.slipstick.com/outlook/rules/outlooks-rules-and-alerts-run-a-script/ actually says add Stop processing more rules.
2. I presume I can simply run this rule (with the script) on messages in the inbox and expect it to work? Do the messages have to be unread?
3. I do actually want to move the message to another folder. How do I do this in VBA

Thanks
 
PS I have no idea if it is significant but . . .
If I try run rules now and select this rule, hte green progress bar only makes it just over half way across before stopping.
 
Hmmm. I forget writing that. :) Of all the actions, stop processing would be the one of the few that shouldn't cause problems.

Yes, you can run it as a test. The script doesn't care about the read state, so it should work.
To move, use this after the display/ send
Item.Move Session.GetDefaultFolder(olFolderInbox).Folders("subfolder-name")


Sample code for other folders is here - http://www.slipstick.com/outlook-developer/working-vba-nondefault-outlook-folders/


To test it with currently selected item, try this. If it works, then we know the problem isn't with the code. I couldn't test it with my template, but it works fine with the default reply.

Code:
Sub TestTemplate()
Dim Item As Outlook.MailItem
Dim oRespond As Outlook.MailItem


Set Item = Application.ActiveExplorer.Selection.Item(1)

' Use this for a real reply
' Set oRespond = Item.Reply

' This sends a response back using a template
Set oRespond = Application.CreateItemFromTemplate("D:\Data\mail\MS-Receipt.oft")

With oRespond
.Recipients.Add Item.SenderEmailAddress
.Subject = "Your Subject Goes Here"
.HTMLBody = "Your reply text goes here." & vbCrLf & _
"---- original body below ---" & vbCrLf & _
Item.HTMLBody & vbCrLf & _
"---- Template body below ---" & _
vbCrLf & oRespond.HTMLBody

' includes the original message as an attachment
.Attachments.Add Item

' use this for testing, change to .send once you have it working as desired
.Display
End With
Set oRespond = Nothing
End Sub
 
1. Ran repair which found errors
2. Tried to run rule and was told to delete those rules with errors. Only rule with an error was unrelated to this issue
3. Copy testTemplate
4. Run macro and it works fine (displays reply email)
5. Run the rule on the inbox and still nothing happens
6. Edit rule to move message instead of run script.
7. Run rule - it works fine (message is moved)
8. Edit rule to run script instead of move message
9. Set breakpoint at first statement (Set oRespond) of script
10 Run this rule on the inbox. Nothing happens.
11 Create error in code and run rule. Nothing happens
so everything points to script not being executed but, given that it is executed when the action is move message, why?!
 
And finally, in case any odd characters had got into the script, I
1. deleted the script
2. manually edited the opening lines of the working macro
3. Tried again. Still nothing.
Is there some form of security that applies to scripts and not to macros that is stopping this?
 
Ahha - progress. If I send a fresh email the rule works correctly.
if I run the rule on the same email (in the inbox) whether it is read OR unread, the rule does not work so it looks as if there is an additional flag somewhere or it happens at a different step in the process.

And finally, just a few of minor things
1. All now seems to work fine (but only for new messages). However, I can find no trace of the sent message in Outlook. Even if I use .display and click Send, I can still not find the message in outlook. Where did it go?
2. I seem to have had to tick the boxes that allow scripts in shared and public folders. I have no idea why as outlook is not connected to an exchange server (rather to a POP3). Why do I have to do this? Does it really matter?
3. Sorry I am not clear on moving items to different folders in VBA
I have the message as Item.
I want to move it to a folder \Work\Porject\Prjname where work is on the same level as inbox. How do I do this ?

Thanks for all your help
 
Another oddity. (see 1 above) Although I can see no trafce of the message, if I try to exit outlook, it tells me that there are unsent messages in the outbox. How can I see them?
 
On the unsent message warning: was the message sent? It might be stuck in the outbox, which should be shown in the folder list. This would explain why its not in the sent folder. It definitely should be moving to the sent folder if the message was sent.
 
the messages were eventually sent but still did not appear in sent items. The two problems that made fixing this take so long were
1. Believing I could run the script on any message in the inbox (as opposed to a newly arrived one)
2. Thinking the script had not worked because there was no message in the outbox nor received by the sending email system.
The light began to dawn when these messages turned up in batches and I finally (bit slow I know!) noticed the connection between telling outlook to send messages (Outlook is set not to send immediately - I find a cooling off period useful!) and batches of your script messages arriving in the other email client.

None of the script messages have ever been seen in 'Sent Items'
Weird, very confusing and most unhelpful!!
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
P Automatic Greeting "Hello Name," when Reply All is clicked Outlook VBA and Custom Forms 1
B resend if no reply and send an automatic reminder Outlook VBA and Custom Forms 0
reza Macro to automatic reply using orignal mail Outlook VBA and Custom Forms 10
I Automatic reply to an email Using Outlook 0
P Daily Automatic Reply Using Outlook 1
C Text reply mail in Outlook 2010 has automatic margin indent Using Outlook 9
P Automatic personalized reply Outlook VBA and Custom Forms 1
P How to get a QR code for automatic signin with Outlook for iOS Using Outlook 5
U Rolling Back Office broke automatic updates Using Outlook 4
Commodore Automatic switch between working offline/online Using Outlook 4
S Outlook 2007 - Automatic purge fail Using Outlook 0
A Automatic forwarding to different people on a rotational basis Using Outlook 2
B Removing Recipients from an automatic response Outlook VBA and Custom Forms 2
J Automatic color category according to variable domains Outlook VBA and Custom Forms 4
N automatic response with an attachment based on the subject line Outlook VBA and Custom Forms 1
E How to send automatic emails in outlook 2010 Using Outlook 1
N VBA Script to Send Automatic Emails from Outlook 2010 Outlook VBA and Custom Forms 1
M Outlook 2016 Desktop - Automatic Rule Processing Using Outlook 3
P Threat to being a spammer while sending automatic Emails through VBA Using Outlook 3
B Automatic picture download and changing email addresses Using Outlook 3
J why won't the automatic send/receive work Using Outlook 7
S rule, automatic replies, restricting them to within the company Using Outlook 1
R automatic signature Using Outlook 0
B Looking for an add-in or a way to send automatic replies based off a list Using Outlook 2
H Automatic excel data added to Certain Emails that are received Using Outlook 3
M Automatic Bcc Using Outlook 2
C starting Outlook 2003 sp3 sets Junk Email setting to 'No automatic filtering' Using Outlook 3
K automatic cleanup folder Using Outlook 3
B How to automatic save Sending or replying contacts e-mails into contacts? Using Outlook 0
J Form design - how do I insert an automatic date/time field? Using Outlook 2
D Stop automatic opening BCM (Business Contact Manager) 1
P propagate automatic formatting to other Outlook folder Outlook VBA and Custom Forms 1
D Re: Propogate Automatic Formatting to Other Folder in Outlook 2007 Outlook VBA and Custom Forms 1
S Sending automatic email from Access using Outlook Outlook VBA and Custom Forms 1
T Code to import address book in automatic mode Outlook VBA and Custom Forms 1
N Reply to Outlook messages by moving messages to a specific Outlook folder Outlook VBA and Custom Forms 1
J Macro to Reply to Emails w/ Template Outlook VBA and Custom Forms 3
J Quick steps delete original email and move reply/sent email to folder Using Outlook 2
nmanikrishnan Auto-reply from default account Using Outlook 1
N Line to move origEmail to subfolder within a reply macro Outlook VBA and Custom Forms 0
A Outlook 2016 Macro to Reply, ReplyAll, or Forward(but with composing new email) Outlook VBA and Custom Forms 0
S How to find emails that I sent that have not received a reply? Using Outlook 7
T Macro to move reply and original message to folder Outlook VBA and Custom Forms 6
A Is there an ID field you can use to pair a reply to the sent email? Outlook VBA and Custom Forms 4
W Reply to email Using Outlook 4
A Edit attachment Save and Reply Outlook VBA and Custom Forms 0
L Macro/VBA to Reply All, with the original attachments Outlook VBA and Custom Forms 2
S Outlook Macro to move reply mail based on the key word in the subjectline Outlook VBA and Custom Forms 0
diver864 vba for a rule to automatically accept meeting requests with 'vacation' in subject, change to all-day event, change to free, don't send reply Outlook VBA and Custom Forms 1
B Adding signature to bottom of VBA reply email Outlook VBA and Custom Forms 1

Similar threads

Back
Top