I wrote a code using Items_add event to manage incoming mailitems.
I recently found out that recall messages and auto-replies (out of office) are not mailitems because my code won`t process them.
I tried googling it but could not find an answer.
So, how can I get incoming recall items and auto-replies that arrive in the inbox?
why not just check what it is? Select the item in your inbox and then run a short bit of code such as below and it will come back and tell you its a report item for recall messages.
Dim objSelection As Outlook.Selection
Set objSelection = Outlook.Application.ActiveExplorer.Selection
MsgBox TypeName(objSelection.Item(1))
Set objSelection = Nothing
Related
I am trying to open and populate emails from MS Project via Outlook. I have done this before from Excel, but when I drop the code into Project I get an error.
'Create and Set New Mail Item
Dim OutlookApp As Outlook.Application
Set OutlookApp = CreateObject("Outlook.Application")
Dim OutlookMail As Outlook.MailItem
Set OutlookMail = OutlookApp.CreateItem(OutlookMailItem)
The error triggers on the Dim OutlookApp line and reads, 'User-Defined Type Not Defined'
What am I forgetting here?
I'm not sure I understand the requirement, so I'm sending a blind shot. In Project 2007 you'll see a combo box at the top right of the screen, probably defaulting to "All Tasks". Choose the date range you want with the info you need and send this to your team along with any encouraging words that you need to motivate them.
Will this help?
As a continuous process to improve our customer service at our helpdesk I'm looking to integrate a functionality in our outlook so that we can reply to existing e-mails using outlook template's (.oft).
My search online mostly gave me results for auto-reply'ing. However this is not what I (we) need.
We are in need for a tool that enables us to select from a list of standard templates (with subject oriented reply's). http://replywith.4team.biz/ Gives a solution in the right direction, however, as with any company, we would like a free tool.
Is this programmable in VBA? And if so, how?
Ours not to reason why, ours but to do and die.
Here is one small, untested, VBA sample based on http://msdn.microsoft.com/en-us/library/office/ff865637.aspx
Sub CreateReplyFromTemplate()
dim currItem As Outlook.MailItem
dim currItemReply As Outlook.MailItem
Dim MyItem As Outlook.MailItem
set currItem = activeinspector.currentitem
Set curritemReply = currItem.Reply
Set MyItem = Application.CreateItemFromTemplate("C:\HelpTopic1.oft")
MyItem.To = currItemReply.To
MyItem.htmlbody = MyItem.htmlbody & currItemReply.htmlbody
currItemReply.close oldiscard
currItem.close oldiscard
MyItem.Display
set curritemReply = nothing
set MyItem = nothing
set currItem = nothing
End Sub
For ways of deploying the VbaProject.OTM file http://www.outlookcode.com/article.aspx?id=28 or see if this works VbaProject.OTM deployment
Alternatively, the free version is built into Outlook.
Reply with a message template via Quick Steps - http://www.msoutlook.info/question/665
Working with message templates - http://www.howto-outlook.com/howto/messagetemplates.htm
If training for this is available, the cost of one day of training for each person could be $300.00 or more.
Of course you can do that in VBA, but would you really want to? You can buy 10 licenses of that tool for $99.50. I don't know where you work, but at most software companies $99.50 will buy you about an hour worth of programmer's time (benefits included). You probably could have bought 1 license if you saved the time it took you to post this question.
Just to add to the answer above, in sub CreateReplyFromTemplate() instead of
Set curritemReply = currItem.Reply
Replace with
Set currItem = Application.ActiveExplorer().Selection(1)
I have a code that checks the recipient of the mail, looks what organization is set in the address book for the recipient and dependent on that sets the "SentOnBehalfOfName"-property of the item. If the recipient is working for client2, he will get the mail from "we_love_to_serve_client2#domain.com".
I call the code either before sending the mail via a button in my ribbon, that calls this Sub:
Sub Signatur()
Dim olApp As Outlook.Application
Dim objMail As Outlook.MailItem
Set olApp = Outlook.Application
Set objMail = Application.ActiveInspector.CurrentItem
Call Signatur_auto(objMail)
End Sub
I do this if I want to know which mail-adress is going to be chosen.
In the itemSend-section of thisOutlookSession I also call the same sub
Call Signatur_auto(Item)
Part of the Signatur_auto (i do not copy that in, the question is too long already...) is dealing with the SentOnBehalfOfName-property, the other part is putting the item into the right folder. The Folder is chosen depending on the SentOnBehalfOfName-property.
Now comes the interesting part: Although the folder-part is always working (which can only be when the SentOnBehalfOfName has worked before), the SentOnBehalfOfName only works "half". In the preview-line the mail sent is shown as from "we_serve_client2#domain.com", but when I open the mail it says it was sent by me. The Client always only sees my address, and also answers to my address - which I do not want....
How cant be, that the same code is having different results dependent on where it is called? Is it a Problem to change the sendonbehalf-field in the item send-section?
Thanks for any Inputs!
Max
Why it does not work?
Try this in ItemSend.
Dim copiedItem As mailItem
Set copiedItem = Item.Copy
copiedItem.SentOnBehalfOfName = "we_love_to_serve_client2#domain.com"
copiedItem.Send
Item.delete
Cancel = True ' In case your setup generates an error message as described in the comments
Why it works? Appears "copiedItem.Send" bypasses ItemSend.
We currently use the following code to create an email in Outlook so that the user can type what they want in Outlook, then when the email is sent, the system prompts them to see if they would like to save the email.
Dim objOutlook As Object
Dim objMessage As Object
Dim objInspector As Object
If strEMail <> "" Then
objOutlook = CreateObject("Outlook.Application")
objMessage = objOutlook.CreateItem(0)
objMessage.To = strEMail
objInspector = objMessage.GetInspector
objInspector.Display()
While Not objInspector.CurrentItem Is Nothing
End While
frmSaveSentEmail.BringToFront()
frmSaveSentEmail.ShowDialog()
The code works fine on Outlook 2003 as long as they are not using Word as their email editor. However, with Word set up as the email editor, the while loop that tests to see if the email object is closed never ends.
Is there a way to handle this differently so that it will work even with Word as the editor?
I am not terribly experienced with programming Outlook via VB.NET, but that loop certainly looks suspicious. Perhaps you should try taking advantage of the inspector's Close event instead of repeatedly checking its CurrentItem property. If I am not mistaken, you should be able to present your dialog within the event handler.
Ended up changing the loop to:
While Not objOutlook.ActiveInspector Is Nothing
End While
This resolved the issue.
I am completely stuck as to how to retrieve details of an email which is either currently selected or open. In fact, I can't find any details on how to access an email. It seems you can traverse the entire folder structure and get all emails, but that doesn't really help me.
I don't suppose I can get some pointers?
And yes, I hate VBA as much as the next developer, but unfortunately about 0.1% of my work involves integration with Outlook.
Cheers.
To get the currently selected emails by looking at the Selection object of the Explorer.
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Set myOlExp = Application.ActiveExplorer
Set myOlSel = myOlExp.Selection
The selection object can contain many items and also contain Items that are of other types than mail (IPM.Note) i.e calendar apps etc. So if you only want mail items you can take a look at the item MessageClass
As for the current email that is trickier as you can multuiple of these open if you just want the top most you can use the Application.ActiveInspector otherwise you should look at the Inspectors Collection of the Application object. You can then get the "item" from the CurrentItem property off the Inspector(remember these can be non mails as well)
Hope full that will get you going
I ended up here as I was looking for a way to use VBA to modify the email that is currently being composed. While the ActiveInspector solution above works if the new email is in a new window, it does not work if replying 'inline' (in the preview pane). For this, I wrote this function:
Private Function CurrentEmail() As MailItem
Dim thisMail As MailItem
If Application.ActiveInspector Is Nothing Then
'editing in preview pane
Set thisMail = Application.ActiveExplorer.ActiveInlineResponse
Else
'editing in pop out window
Set thisMail = Application.ActiveInspector.CurrentItem
End If
If thisMail Is Nothing Then Exit Function
If thisMail.Sent Then Exit Function 'ignore sent items
Set CurrentEmail = thisMail
End Function