Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to change "reply to" address 1

Status
Not open for further replies.

mchoss

Programmer
Feb 11, 2002
87
0
0
GB
Outlook 2003

Dear all,

I cannot find code that will work with outlook 2003 objects to allow me to write a macro to change the "have replies sent to" option (or the 'from' field).

I want to assign the macro to a button to allow me to change the 'reply to' field at my discretion (but with a set alternative address) - clearly this would be quicker than having to go to options each time and select the address.

The examples i have seen all refer to mailitem which doesn't seem to be available in my object browser.

An code examples for a macro to achieve this would be much appreciated.

Thanks in advance
 
One way or another, if you want to change a mail item, you have to access the MailItem object (unless you use the menus).

Assuming you want your macro to run when you are creating (or editing) a mail item, then [blue][tt]ActiveInspector.CurrentItem[/tt][/blue] will get it for you and I guess you want to set the [blue][tt]ReplyRecipients[/tt][/blue]

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Hi Tony,

Thanks for the response. I have tried various code examples but i cannot get any to work correctly and i am concerned that the editor doesn't 'recognise' standard objects such as the ActiveInspector and MailItem. Could it be because i have Word set as the default editor?

In any case, i would be extremely grateful if you could propose a standard code example to get the current mail item and alter the ReplyRecipients property.

Thanks once again for your help.
 
I don't have Outlook 2003 installed anywhere to check, and I'm not an Outlook person, so this is guesswork.

When using Word as Outlook Editor, what Application are you addressing by default in VBA? Word or Outlook?

If it's Outlook, this should work:
Code:
[blue]Dim MyMail As MailItem
Set MyMail = ActiveInspector.CurrentItem[/blue]

If it's Word, you may need to explicitly reference Outlook, something like this:

Code:
[blue]Dim MyMail As MailItem
Set MyMail = [red]Outlook.[/red]ActiveInspector.CurrentItem[/blue]

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
mchoss,

could it be that you have been trying to reply from the main Outlook window with the mail only opened in the preview pane?
THAT won't work.
You have to assign the macro to a button on the mail window, not of the Outlook window.
!

Cheers,
miS

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Thanks for the replies guys,

Unfortunately i think security is the issue. I have indeed been trying to write the macro by accessing the macro facility from a new mail item itself. The fact that the standard objects above are not recognised by the editor is, i am led to believe, to do with security policy on the lan i am on.

Ah well, looks like i will have to accept defeat at the hands of the administrators this time!

Thanks again for your efforts.
 
If you are using Exchange (of which I know nothing), I can believe there may be some issues but, if you can run macros, then security is unlikely to be the issue - did you try using [tt]Outlook.ActiveInspector[/tt]? And, if so, what was the error?

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Tony,

Here is the code i am running:

-----------------------
Sub test()

Dim objOutlook As Outlook.Application
Dim myMail As Outlook.MailItem

Set objOutlook = CreateObject("Outlook.Application")
Set myMail = objOutlook.ActiveInspector.CurrentItem

myMail.ReplyRecipients.Add "email@address.com"

End Sub

-------------------------

However, on compile it falls at the first hurdle. I get the error at the Outlook.Application line: user-defined type not defined.

As mentioned, the editor doesn't pick up any of the objects above.
 
That's because you don't have a reference to the Outlook library in your Word Editor project. Either add a reference via Tools > References, or change the declarations to:
Code:
[blue]Dim objOutlook As Object [green]' Outlook.Application[/green]
Dim myMail As Object [green]' Outlook.MailItem[/green][/blue]

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Aaargh!
"Could it be because i have Word set as the default editor?"

One should always read carefully. Well spotted, Tony!
[thumbsup2]

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Tony,

That is fantastic - it works! Thank you so much.

My only problem now is that when i run the macro, outlook throws me a warning dialogue stating that:

"A program is trying to access addresses you have stored in outlook. Do you want to allow this?

If unexpected, it could be a virus and you should choose no"

There is an option to allow access for up to 10 minutes.

Do you know of any way of overcoming this issue? It would be helpful if i didn't have to keep dealing with this dialogue once access timed out.

Thanks again.
 
That is called the Object Model Guard - it is designed to prevent Outlook being compromised and requires human intervention. There are ways round it, in particular a program called ClickYes which simply keeps a look out for that particular prompt and automatically, you've guessed it, clicks Yes. There is also a popular program called Redemption which, I think, does a bit more but I have never investigated it. Google for either of those.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top