On one PC using Excel VBA and Outlook ExchangeConnectionMode results in 0 which means it is not connected to Exchange while Outlook is closed. We use Office 365 on a recent Windows 10 Version.
https://learn.microsoft.com/de-de/office/vba/api/outlook.account.exchangeconnectionmode
I assume there is an option in Outlook to keep Exchange connected when Outlook is not open.
Set myApp = CreateObject("Outlook.Application")
Set myNamespace = myApp.GetNamespace("MAPI")
MsgBox(myNameSpace.ExchangeConnectionMode) ' returns 0
I could figure it out actually. As i expected it had to do with the account settings. In it, you need to have "Use Cached Exchange Mode" enabled. With having it enabled it returns to mode 400 which will allow accessing cached mails
Related
At work we are using Outlook 2016 and have recently upgraded to Microsoft Exchange. We have various VBA programs, run from Excel or Access, which create Outlook emails and save them in the Drafts folder, ready to be checked and sent by hand after running the program. These programs used to work before we went over to Microsoft Exchange.
Now, when I double-click one of the emails that were saved in Drafts by whichever program I was running, Outlook refuses to send it, and reports the error "The operation failed." No other information or error codes are provided. One of my colleagues has the same problem. Others do not. In theory we should all have the same version of Outlook and Microsoft Exchange.
I have discovered that I can reproduce this problem by running code directly within Outlook. I did Alt-F11, enabled macros, inserted a module and pasted the following code into the window.
Sub TestEmail2()
Dim OutMail As Outlook.MailItem
Dim EmailTo As String
Dim EmailSubject As String
EmailTo = "me#myaddress.com"
EmailSubject = "Test Email 2"
Set OutMail = Application.CreateItem(0)
With OutMail
.To = EmailTo
.Subject = EmailSubject
.Save
.Close 0 ' olSave
End With
Set OutMail = Nothing
Debug.Print "Finished"
End Sub
If I set a breakpoint at "Set OutMail = Nothing", and run the code to that breakpoint (so "Set OutMail = Nothing" hasn't executed yet), then go to my Drafts folder and try to send the email, it will go without errors. If I rerun the code and allow it to run to completion, I get the error if I try to send the email it generates.
I would like to either (1) find a workaround that I can add to the code so I can send messages or (2) find out what is wrong with my Outlook profile so I can ask our IT helpdesk to change it, or change it myself. I don't want our IT helpdesk to reset my profile to the default settings and lose my customisations.
That usually indicates that the address book is corrupt. Try to use the Resolve or ResolveAll methods to resolve recipients against the address book.
This issue may also occur when a Google Apps Sync for Microsoft Outlook account and a Microsoft Exchange Server account are configured in the same Outlook profile. See "The operation failed" error when you send email messages in Outlook for more information.
Besides, it is also suggested to try repairing Office via Control Panel and see if the issue can be fixed. Also, you may try repairing your PST files.
I have code to generate an email based on data on a userform.
It worked for a long time across multiple machines, but when I changed machines it started throwing a run-time error 13 type mismatch on on the CreateItemFromTemplate method in the following section:
Private Sub AcaoEnviar_Click()
Dim OutlookApp As New Outlook.Application
Dim EmailKRI As Outlook.MailItem
Set EmailKRI = OutlookApp.CreateItemFromTemplate(PATH_EMAIL_TEMPLATE)
The code still runs on other machines, suggesting the problem is local. My Outlook library is the same as on the other machines, and the only difference I´m aware of is that I´m running it on a 64-bit system and 32-bit office, while most others have 32-bit systems (one other has the same 64-bit setup and runs fine).
Changing the object declaration from Outlook.MailItem to Object seems to solve the problem, which I think eliminates problems with Outlook's programmatic access, and in any case, my Antivirus status is valid.
I'm still confused as to why such an error would occur only with me.
Is there any solution so that I can go back to early binding for that email object?
You will get that error if CreateItemFromTemplate returns something other than MailItem object. Are you sure the OFT file is for a regular mail item.
As a test, declare EmailKRI as a generic Obejct and at run time check the value of the EmailKRI.Class property. It is supposed to be 43 (OlObjectClass.olMail) for the regular MailItem objects.
I have a vb.net script that sends automatic emails from Outlook. It currently works in the Office 2010 Suite. I upgraded my environments to 2013 and now it is not working. What I'm doing isn't complicated. All I want to do is grab a .pdf and attache it to an email. Then add the recipients and send the email. The place where it crashes is the actual sending of the email. It throws this execption
System.Runtime.InteropServices.COMEception occurred in Microsoft.VisualBasic.dll
Additional information: Operation aborted (Execption from HRESULT: 0x80004004 (E_ABORT))
I'm thinking because I upgraded environments something isn't referenced correctly. But I can't seem to find a fix. Below is my code, any help would be greatly appreciated! Thanks in advanced.
Imports Outlook = Microsoft.Office.Interop.Outlook
Module Module1
Sub main()
sendEmail()
End Sub
Public Sub sendEmail()
Dim ol As Object
Dim mail AS Object
ol = CreateObject("Outlook.Application")
mail = ol.CreateItem(0)
mail.To = "email#example.com"
mail.Subject = "Subject Line"
mail.Body = "Body text"
mail.Attachments.Add("path\to\attachment.pdf")
mail.Send() 'crashes on this line
mail = Nothing
ol = Nothing
End Sub
End Module
Also I am running on Windows 7 with the Office 2013 suite. Looking at the App.config my supported Runtime version is v4.0 and the .NetFramework version is v4.5
Since your solution is automating Outlook cross-process you first need to ensure that these types of applications are authorized so check your anti-virus state in Outlook's Trust Center:
https://msdn.microsoft.com/en-us/library/office/ff864479.aspx
I would also wrap the CreateObject call in a Try/Catch block to ensure that isn't failing to begin with. Also make sure that you have an Outlook profile created and that your application isn't running under a non-authorized security context like via a Task Scheduler process or in a web application.
I have a 1-min delay on all emails and want to assign a category set up as an exception to the rule to send immediately.
I created the macro but it stopped working.
Public Sub CategoriesButton()
Dim Item As Outlook.MailItem
Set Item = Application.ActiveInspector.CurrentItem
Item.Categories = "SendMe"
Item.Save
End Sub
Interesting - I just had the same issue. Working perfectly but then I restarted Outlook and it stopped working - for no apparent reason.
Took me a while to work this out - but when you restart Outlook it applies Macro security permissions to your macro.
If you haven't digitally signed your macro, the default behaviour is to prevent it from running.
You can relax the security settings so that Outlook with either ask your permission to run macros, or just run all macros regardless (this latter option is probably not a good idea!)
You can self-sign your own macro, there's quite a good guide to doing that here: http://www.slipstick.com/developer/how-to-use-outlooks-vba-editor/
But annoyingly it seems you will always get a notification, even with a signed macro... so it's probably easier to just change the security settings to 'notification for all'.
Hope this helps - the code you posted certainly helped me, it was exactly what I was looking for, also to control 1 minute delay!
Man, every time I go near macros in Outlook I end up losing half a day or so...
I am developing an application where I want to sync the outlook calendar, mail, etc.
The piece of code which is there with me is working fine for outlook 2003, 2007.
but I don't know what's the problem it is causing for outlook 2010.
I use the following:
redemption dll 5.4 version-32 bit
office object core 14 dll-32 bit
office -32 bit version
visual studio 2008
I am getting this error:
Cannot create ActiveX component.
On the following line:
session = CreateObject("Redemption.RDOSession")
Where session is:
Dim session As Redemption.RDOSession
After which the following error is displayed:
Either there is no default mail client or the current mail client cannot fulfill the messaging request
I have tried various things but it's same. I also reinstalled, repaired outlook, repaired registry.
Any ideas?
this worked for me:
first, I will say I used the Customize.exe that comes with redemption to create a dll called ffloader.dll
Next, I registered that dll as follows (32 bit)
regsvr32 ffloader.dll
Finally in the vb.net code I created the session as follows:
Dim Session As Redemption.RDOSession = CreateObject("ffloader.ffRDOSession")
Hope that helps!