Outlook's button 'Attach File' does not work

T

Tanya

I am creating simple mail using Microsoft.Office.Interop.Outlook. I do not
want to attach file in the code - I need simple mail without any attach. Mail
is successfully created and opened, but after this button 'Attach File' does
not work (it could be clicked, file could be selected but it is not
attached). Here is simple code:

Dim Outlook As New Outlook.Application
Dim OutlookMessage As Outlook.MailItem
OutlookMessage = Outlook.CreateItem(OlItemType.olMailItem)
OutlookMessage.Display()

I am using Outlook 2007.

Could anyone help me with this?
 
K

Ken Slovak - [MVP - Outlook]

Where is this code running? Is it in an Outlook addin or standalone code or
what?

Do you get any errors when you try to attach something or does it just not
work?

Does the Attach File button in the Insert tab work?

Does Attach File work if you open an item yourself and not with code?

Offhand I can't see any reason why that code wouldn't allow an opened item
to attach things.
 
T

Tanya

This code is running from standalone application. It is VB.Net code, you
could run it and then in opened Outlook window press Attach File button in
the Insert tab. As I said it works a bit funny - attached file is not shown
but will be sent. In case new mail is created from Outlook this button works
fine. Nevertherless, after opening saved .msg file - same strange behaviuor.
(Outlook must be closed before doing this).
 
K

Ken Slovak - [MVP - Outlook]

Please leave some of the preceding thread, it makes it very hard to maintain
context otherwise.

I'm completely confused now. What do MSG files have to do with anything?

You're now saying if the new mail is created from Outlook the button works?
That's what you said didn't work before.
 
T

Tanya

Here is code in VB.Net:

Dim Outlook As New Outlook.Application
Dim OutlookMessage As Outlook.MailItem
OutlookMessage = Outlook.CreateItem(OlItemType.olMailItem)
OutlookMessage.Display()

This code is running from standalone application. It creates empty mail.
This mail is opened in Outlook window. This window has tab 'Insert' which has
button 'Attach file'. If you run this code and press this button you will
see that it works strange - file can be selected but won't be shown.

In case new mail is created from Outlook this button works fine.
 
K

Ken Slovak - [MVP - Outlook]

I can't repro this here. Using code like yours produces an email where all
the buttons and menu items work correctly.
 
K

Ken Slovak - [MVP - Outlook]

Please leave part of the preceding thread in your posts.

So if Outlook wasn't already running you get this? Then start Outlook, use
GetNameSpace("MAPI") to logon and maybe wait a bit to let Outlook finish
starting up. Then do the rest of the code. If that isn't enough you might
need to display Explorer UI (using the GetExplorer method).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top