Link to home
Start Free TrialLog in
Avatar of Rajesh Dalmia
Rajesh DalmiaFlag for India

asked on

Add Button in Outlook Message Window

Hello all,

I want to write a VB application which will "Add a New Button in Outlook Message Window". Every time I open up any message this button should aapear. My outlook messages can have more than one attachment. This button, when clicked, will ask me for a path and will save all the attachement in that specified path in one go, so that I don't need to save each message seperately.

Can anybody help?

Thanks
Avatar of Rajesh Dalmia
Rajesh Dalmia
Flag of India image

ASKER

I am aware that Outlook already has Save Attachments option in the File Menu which will do the same thing. But actually this button will not only save the attachments but will also forward the email to few pre definied email addresses. Everytime I don't want to click Forward and then key in the email address.
So you if can guide me how to creat the button in message window, other things I can add in the code.

Thanks
Hi rdonline1,

You don't need a VB application, just a bit of VBA scripting.  This is easily done, but there is a catch.  Forwarding messages is going to trigger Outlook's built-in security causing a dialog-box to pop up warning that an application is attempting to send on your behalf and asking for your permission to allow it to continue.  You can avoid this by having the code simply display the message and allowing you to click Send.  I'll post the rest of the VBA code for adding the button shortly.

Cheers!
ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The very 1st line of code

Public WithEvents myOlInspectors As Outlook.Inspectors, _
    WithEvents olkControl As Object

is giving me error.
"Compiler error:
Expected: identifier"
My fault.  Change

    WithEvents olkControl As Object

to

    WithEvents olkControl As CommandBarButton
Few points:

1. During attachment save it should show Browse Button to select folder.
2. For message forward I don't want to show the Forward Message Window. It should directly forward the message without any warning message.
1.  That wasn't mentioned in your question.  You said "will ask me for a path " and that's what this code does.  I'll look and see how involved it'd be to add a browse capability.  If it's not too involved, then I'll add it to the code.

2.  As I mentioned in my 11:04AM post on 6/24, the code can send, but you'll get that security dialog-box each time it does.  That's going to be way more annoying than having to click Send.  If you want it to send instead of displaying, then change

    olkForward.Display

to

    olkForward.Send
Hi BlueDevilFan,

Thank you very much for your response. It was my fault not to mention that I want a Browse Button. Ok never mind, this is not important and for the warning message I will try to show the foward window.
But my last question:
Is there any way that this whole thing can be done using VB. As a programmer it is easy for me to follow the process that you specify but I dont want my client (for whom I can doing this) to go through the whole process. It should be installed as a outlook add-in and he can un-install this later.

I want to mention that in the very 1st requirement I specified that I want a VB application.
> in the very 1st requirement I specified that I want a VB application.
Yes, I noticed that.  Some questions authors don't draw a distinction between an Outlook macro and a VB application, so I wasn't sure in this case.  With a couple of modifications this could be a VB application, but it really doesn't make sense to do that.  What would we gain by making this a full-fledged VB program?  It won't have an interface and as a separate app the user would have to be careful about starting it when Outlook wasn't running and would need to remember to close it one they'd shut Outlook down.  You mention that you "don't want my client to go through the whole process".  Go through what process?  Once the code is in place there's nothing to do.  If you're talking about the process of putting the code in place, then I submit that as an app or add-in the user would have to run an installation program or copy files to certain folders, etc.  With the exception of sending, which I've mentioned is going to be a problem, everything is done automatically.  You mention doing this as an Outlook add-in, which is different from both a VB application and a macro.  Doing this as an add-in would make more sense than doing it as a VB app, but I'm still not sure I see the point.  What's gained?  Without regard to which approach you ultimately use, the code remains essentially the same.  
Thanks for your quick response. May be I was not too clear in my comment. Regarding Vb app what I meant is not that the user have to run the app every time with outlook. But what I intended to say, is it possible to run the commands (copy paste the code, setting the security level etc) from a VB app so that I can do the coding in the exe and user have to click a button and every thing will be done. After that everything will work as you specified and ther user dont need to run the vb program again.
Actually I dont have much idea about add-in. So if you give me some information about how the add-in can be useful in this case (instead of VB) and also how to make an add-in for this, then that will be a great help.

Thanks
Oops, sorry, I didn't understand your intent for the VB app.  I don't think what you described is going to work.  I won't say that it can't work, I've seen some awfully inventive solutions to various things, but I can say that there's no provision for doing this from VB.  Microsoft hasn't provided any APIs in Outlook or CDO for doing this.  Changing the security level from code would be a dangerous thing to allow anyway since it'd give a hacker or virus author a potential means of altering Outlook's security setting to allow their code to work better.  Microsoft also didn't provide any programmatic means of getting macro code into Outlook.  I think their design philosophy must've been that macros would be written by individual users for their own use and that developers would distribute code they created as add-ins.  Here are a coupleof links to more information about add-ins.

http://www.outlookcode.com/d/comaddins.htm
http://www.microeye.com/resources/template.htm
Thank you very much BlueDevilFan for your reply.
You're welcome.