Archived Comments for the "Getting a Handle on Your E-mails With VBA" article
The comments for this article were not migrated when OfficeZealot upgraded our blog engine from .Text to Community Server because the article was just that - an article, and not a blog post. So here are the archived comments that were once displayed on the original article page:
# re: Getting a Handle on Your E-mails with VBA 9/19/2004 7:17 AM
Great article. I cannot get it working though.(too newbie probably).
I get comments about macro's not being turned on: What should I do, I know not much about Macros, doing everything in VBA.
Where can I put the event procedures (like objMailItem_OPen) when I need them to store data in access?
# re: Getting a Handle on Your E-mails with VBA 9/20/2004 8:14 AM
Check your macro security settings - Tools | Macro | Security. Also see this for more info:
Visual Basic and VBA Coding in Microsoft Outlook:
http://www.outlookcode.com/d/vb.htm
As for storing information in Access, it is up to you to determine where and how to do that. I don't really have enough information about what you want to do to give you some advice on that.
# re: Getting a Handle on Your E-mails with VBA 9/20/2004 11:11 AM
thanks for fast reply.
I'l ; figure out the macro thing.
the other question: i would like to create it in such a way, that whenever an appointment is deleted in outlook, the date and subject of the deleted appointment are stored in an access table.
Should I call access from Outlook? or should I startup access as soon as access is started, just in case an appointment will be edleted?
Thnx,
martijn
# re: Getting a Handle on Your E-mails with VBA 9/20/2004 11:47 AM
You'd have to monitor the Item_Remove event for the Calendar's MAPIFolder.Items collection. However, this doesn't tell you what item was removed. You'd have to code some before and after checks to determine what was deleted. However, if the Appointment was deleted from the Inspector itself, then you can trap the AppointmentItem_BeforeDelete event.
Basically, you have to put the code in Outlook and not Access.
# re: Getting a Handle on Your E-mails with VBA 9/20/2004 1:38 PM
again, thanks a lot for very fast reply.
May I be so bold as to ask for one more hint: can you give a direction on what you mean by "before and after checks?"
I do not suppose that you aim at procedures like:
Private Sub objAppointmentItem_BeforeDelete(ByVal Item As Object, Cancel As Boolean), as you suggest these for the Inspector-event.
Forgive me for being a newby, trying real hard to make a complex application and asking these silly questions...
regards, Martijn
# re: Getting a Handle on Your E-mails with VBA 9/20/2004 2:06 PM
If you expect the user to have the Appointment Item message open, then you can trap the delete from there. See the objInspectors_NewInspector event in my code sample above. Here you would look for olAppointment items instead of olMail. Then you can put your code to update your Access database in the BeforeDelete event.
Otherwise, if you need to check when the user is deleting appointments from the folder, it is a lot more work.
# re: Getting a Handle on Your E-mails with VBA 9/20/2004 2:34 PM
Is there a way to block the option for the user to delete appointment items from the folder (or by just clicking and deleting in the agenda)? Than I could guide the user towards the inspector and there monitor if the item is being deleted.
Since I have a list of the appointments I want to monitor in being deleted (the lessons that are planned (typically in the order of 100 lessons), when I can get a signal whenever anything is being deleted, could I check in a loop like:
while not rstplannedlessons.eof
if being_deleted.applicationitem.id= rstplannedlessons.id then
rstplannedlessons.removed = true
end if
loop
The code is working btw. I can monitor the events from your examples, when I read or close a window, I get promted!
I am getting less and less newby-like ;-)
regards, Martijn
# re: Getting a Handle on Your E-mails with VBA 9/21/2004 11:39 AM
Sorry, you would not be able to reliably block certain items from being deleted within the folder view.
You can tell which items are being selected from the Explorer.Selection property. This can be used to get a before and after snapshot of items that were deleted, however it has to be used in conjunction with an Inspector wrapper. This is a very complicated technique that is difficult to explain to new programmers. You're best bet is to study the Explorer wrappers used in the ItemCB example from the Resources section of http://www.microeye.com (I think Inspector wrappers are used in the example as well).
Otherwise, if you are using Exchange you can write event sinks to trap everything that is going on at the folder level, including deleted items. Event Sinks are very complicated to write though. See this link for more info:
Microsoft Exchange Scripting and Routing:
http://www.outlookcode.com/d/scripting.htm
# re: Getting a Handle on Your E-mails with VBA 9/21/2004 4:12 PM
Great article. The sample prompts made it very easy to adapt to my requirements.
Many thanks
Paul
# re: Getting a Handle on Your E-mails with VBA 10/18/2004 3:15 AM
Great article, just what I have been looking for. However i want to trap when a mail item is viewed in the preview pane, or simply when it is selected in the folder, the Open or Read events only appear to occur when the item is actually opened.
Any ideas please?
# re: Getting a Handle on Your E-mails with VBA 10/18/2004 3:16 AM
Great article, just what I have been looking for. However i want to trap when a mail item is viewed in the preview pane, or simply when it is selected in the folder, the Open or Read events only appear to occur when the item is actually opened.
Any ideas please?
# re: Getting a Handle on Your E-mails with VBA 10/18/2004 12:11 PM
Martin: You would need to use the Explorer.SelectionChange event in combination with the Selection property to determine what is currently selected. The only way to tell if the Preview Pane is enabled is by evaluating the 'previewpane' element from the View.XML property value for the current folder view.
# re: Getting a Handle on Your E-mails with VBA 11/4/2004 4:49 PM
How to get the SMTP Message-ID from the outlook object?
# re: Getting a Handle on Your E-mails with VBA 11/4/2004 8:21 PM
John: see this link:
http://www.slovaktech.com/code_samples.htm#InternetHeaders
# re: Getting a Handle on Your E-mails with VBA 11/18/2004 2:42 AM
Nice article. But how does this macro work with Office 2000 SP3, which disallows any automated action on emails in outlook?
# re: Getting a Handle on Your E-mails with VBA 11/18/2004 8:02 AM
My code has no specific issues with differing Outlook versions, but it is dependent on how you've configured your macro security settings. See this article for more details:
How to Prevent the VBA Macro Security Warning in Microsoft Outlook 2000:
http://msdn.microsoft.com/library/en-us/dnout2k/html/oldigitalsignature.asp?frame=true
# re: Getting a Handle on Your E-mails with VBA 11/29/2004 4:47 PM
great article, thanks, i've been searching high and low for something like this.
-todd
# re: Getting a Handle on Your E-mails with VBA 12/14/2004 6:13 AM
Great Article - i have been looking everywhere for trapping events.
The database idea is something i would like to try out but i have no idea on how to connect to a db from outlook.
Could you give me a helping hand?
Thanks
# re: Getting a Handle on Your E-mails with VBA 12/14/2004 8:11 AM
Nick: Thanks for the kudos! As for working with databases in Outlook, it is no different than any other program. If you know how to use VB or VBScript to work with OLEDB or ODBC datasources, you can hook into Access, SQL or any other DB the same way. The only trick is knowing where to put your code, and when to write/read from the db.
The best resource to start with is here:
Connecting Outlook and Exchange to Databases:
http://www.outlookcode.com/d/database.htm
# re: Getting a Handle on Your E-mails with VBA 12/21/2004 3:22 PM
Hi
I am trying to adapt the code for closing an e-mail which asks for a location to save an attachment but cannot seam to only execute code if there is an attachment.
I am up 2 here but cannot seam to stop the code when there is not an attachment.
Dim myolApp As Object
Dim myMessageItem As Object
Dim myAttachmentItems As Object
Dim myJobnumber As String
Dim MyDrive As String
Dim Title As String
Set myolApp = CreateObject("Outlook.Application")
Set myMessageItem = myolApp.ActiveInspector.CurrentItem
Set myAttachmentItems = myMessageItem.Attachments
If len(myAttachmentItems) <> nothing then
myJobnumber = InputBox("Job Number prefix?", Title, "99999")
If myJobnumber = "" Then GoTo Getout
MyDrive = InputBox("Save on which drive?", Title, "P:\")
If MyDrive = "" Then GoTo Getout
For Each myAttachmentItems In myAttachmentItems
myAttachmentItems.SaveAsFile MyDrive & myJobnumber & "-" &
myAttachmentItems.DisplayName
Next
Getout:
Set myolApp = Nothing
Set myMessageItem = Nothing
Set myAttachmentItems = Nothing
# re: Getting a Handle on Your E-mails with VBA 12/21/2004 3:51 PM
Nick: This line is your problem:
"If len(myAttachmentItems) <> nothing then"
You should use this line:
If Not myAttachmentItems.Count = 0 Then
# re: Getting a Handle on Your E-mails with VBA 12/23/2004 10:28 AM
Excellent article. My goal is to be able to display the internet headers in a seperate dialog box as you view the messages. I implemented the explorer event and it works - sort of. Since the internet headers require the user to confirm that it is ok to access addresses, there is some issue where outlook freezes, I have to close a window (which never shows up) in the task bar, then it continues.
Seems like a bug. So,
How can I turn off the security "feature" that asks me to confirm that it is ok to access the address information? Thanks.
# re: Getting a Handle on Your E-mails with VBA 12/23/2004 1:01 PM
Seth: See this link for more info on the security prompt:
Microsoft Outlook "Object Model Guard" Security Issues for Developers:
http://www.outlookcode.com/d/sec.htm
BTW, I gather you are using CDO to access the PR_TRANSPORT_MESSAGE_HEADERS value?
# re: Getting a Handle on Your E-mails with VBA 1/12/2005 8:49 AM
Great article
I have tried the code and it helps to explain what the code is doing when msg boxes appear.
Is there a way to differentiate between an e-mail that is received and then opened versus a new e-mail which is going to be created and then sent!
Because at the moment the code considers them both the same - i.e an open mail item.
Thanks
Nick
# re: Getting a Handle on Your E-mails with VBA 1/12/2005 9:10 AM
There are many properties of the MailItem object that you can inspect for blank values that will indicate a message is new. EntryID is a good one, as it is only populated with a unique value when the message is saved/delivered. See also ReceivedByName, ReplyRecipientNames, ReplyRecipients.Count (0), SentOn, etc.
# re: Getting a Handle on Your E-mails with VBA 1/12/2005 11:34 AM
i have tried this and this is my code so far.
i have managed to solve forwarding but not reply..
could give me an example to match up with my code?
Dim WithEvents colInspectors As Outlook.Inspectors
Private Sub Application_Startup()
Set colInspectors = Application.Inspectors
End Sub
Private Sub colInspectors_NewInspector(ByVal Inspector As Inspector)
' your code to work with Inspector goes here
' if you want to work with the actual item that's opened,
' use this:
'Dim objItem As Object
'Set objItem = Inspector.CurrentItem
Dim myolApp As Object
Dim myMessageItem As Object
Dim myAttachmentItems As Object
Dim myJobnumber As String
Dim MyDrive As String
Dim Title As String
Set myolApp = CreateObject("Outlook.Application")
Set myMessageItem = Inspector.CurrentItem
Set myAttachmentItems = myMessageItem.Attachments
'Set objreply = myMessageItem.Reply
With myMessageItem
If .To = "" Then GoTo Getout
'If Not objreply = "" Then GoTo Getout
'basic info about message
Debug.Print .To
Debug.Print .CC
Debug.Print .Subject
Debug.Print .Body
If .UnRead Then
Debug.Print "Message has not been read"
Else
Debug.Print "Message has been read"
End If
myJobnumber = InputBox("Title prefix?", Title, "99999")
If myJobnumber = "" Then GoTo Getout
MyDrive = InputBox("What is the case number", Title, "Case Number")
MyDrive = "C:\" & MyDrive & "\1\"
If MyDrive = "" Then
Dim AbortRetryIgnore
AbortRetryIgnore = MsgBox("Not a valid case number - Retry or Cancel?", vbRetryCancel + vbCritical)
Select Case AbortRetryIgnore
Case vbRetry
MyDrive = InputBox("What is the case number", Title, "Case Number")
Case vbCancel
GoTo Getout
End Select
End If
If Dir(MyDrive, vbDirectory) = "" Then
MsgBox "No such Customer!"
GoTo Getout
End If
.SaveAs MyDrive & myJobnumber & "-" & myMessageItem & ".txt", olTXT
End With
DoEvents
'start of attachment process
For Each myMessageItem In myAttachmentItems
myJobnumber = InputBox("Title prefix?", Title, "99999")
If myJobnumber = "" Then GoTo Getout
MyDrive = InputBox("What is the case number", Title, "Case Number")
MyDrive = "C:\" & MyDrive & "\1\"
If MyDrive = "" Then
'Dim AbortRetryIgnore
AbortRetryIgnore = MsgBox("Not a valid case number - Retry or Cancel?", vbRetryCancel + vbCritical)
Select Case AbortRetryIgnore
Case vbRetry
MyDrive = InputBox("What is the case number", Title, "Case Number")
Case vbCancel
GoTo Getout
End Select
'If Dir(MyDrive, vbDirectory) = "" Then
'MkDir MyDrive
End If
'myMessageItem.SaveAsFile MyDrive & myJobnumber & "-" & myMessageItem.DisplayName
If Dir(MyDrive, vbDirectory) = "" Then
MsgBox "No such Customer!"
GoTo Getout
End If
myMessageItem.SaveAsFile MyDrive & myJobnumber & "-" & myMessageItem.DisplayName
Next
Getout:
Set myolApp = Nothing
Set myMessageItem = Nothing
Set myAttachmentItems = Nothing
End Sub
# re: Getting a Handle on Your E-mails with VBA 1/12/2005 1:02 PM
Nick: I'm not really sure exactly what you are trying to do here. What do you need to do if the message being opened is a new message? Also, what do you need to do differently when you reply to or forward an existing message?
# re: Getting a Handle on Your E-mails with VBA 1/13/2005 6:18 AM
The point of the code is when a new e-mail has been opened then the attachment and the content of the new e-mail is saved to a particular location.
But i do not want the code to activate when a message is replied to!
# re: Getting a Handle on Your E-mails with VBA 1/13/2005 8:54 AM
Ah, I see. Then you want to move your attachment code to the objItem_Open event (if you have objItem declared WithEvents in that module). Check to see if this is an existing/new message there.
# re: Getting a Handle on Your E-mails with VBA 1/13/2005 9:43 AM
Nice page, good idea :)
Is it possible, to check if a message that is displayed with .Display is sent or cancelled?
Maybe it's already here but I just cannot get it...
I have a module like:
Sub NetworkMail(Optional IntLevel)
'here I get some info from an Access Form
'then generate the mail...
otlMail.HTMLBody = strMailBody
otlMail.To = strCim
otlMail.Subject = strSubject
otlMail.Display
End sub
I have a button with NetworkMail() to the onclick event...
Where shall I put this monitoring thing you explained?
Thanks,
Marton
# re: Getting a Handle on Your E-mails with VBA 1/13/2005 10:24 AM
Did you implement the clsMailItemTrapper class as explained above? Most of your code will take place in the events exposed by that class.
You don't have to worry about calling Display in the above examples, as the events fire for already opened items. If you need to know if the opened item is sent, trap the Send event. If it doesn't fire, it is not sent.
I suggest just installing and using the demonstration code above to get an idea of how this works first; then implement your custom code.
# re: Getting a Handle on Your E-mails with VBA 1/13/2005 11:12 AM
Hello,
Start by saying, I'm not at all an expert in VB. We would like to do something like what you are describing above, however, want to hyperlink (not attach) a file.
Would you advise what modifications need to be made?
Thanks in advance for your help.
# re: Getting a Handle on Your E-mails with VBA 1/13/2005 1:43 PM
Roboin: All you have to do is provide the text for the URL or UNC path to the file in the body of the e-mail message. Either:
file://C:\TEMP\text.txt
or
http://www.domain.com/foldername/filename.txt
Outlook will automatically make it a clickable hyperlink.
# re: Getting a Handle on Your E-mails with VBA 1/14/2005 5:19 AM
Hi,
OK, I forget to tell...
I use an access database and generate a mail with a code.
Then call .Display to allow the user to view the mail and make necessary modifications.
I'd like to monitor if the mail is sent or cancelled. It'n not running on my computer so I cannot modify the outlook application_start event.
Is there any way to do the whole thing from an external app like Access?
Thanks,
Marton
# re: Getting a Handle on Your E-mails with VBA 1/14/2005 6:09 AM
Eric
I have spent quite a lot of time trying to do this and it is more involved than i first thought.
This is the code which works but has flaws in it.
It does all i want and i have stored it in ThisOutlookSession.
It has as mentioned flaws with reply,forward and also i have found out flaws when contacts are opened or any kind of outlook item when opened.
Can you offer perhaps a better way of doing this!
All i want to do is when a new e-mail is opened - save the content of the e-mail and if an attachment then save that as well to a paricular location based on the input given in the msg boxes - i.e the case number relates to a folder already on the c:/ drive - i.e. if the user inputs 1234 it will store the files in 1234 folder if it exist!!
can you try running this code and give me some help... I am lost now!!
Dim WithEvents colInspectors As Outlook.Inspectors
Private Sub Application_Startup()
Set colInspectors = Application.Inspectors
End Sub
Private Sub colInspectors_NewInspector(ByVal Inspector As Inspector)
' your code to work with Inspector goes here
' if you want to work with the actual item that's opened,
' use this:
'Dim objItem As Object
'Set objItem = Inspector.CurrentItem
Dim myolApp As Object
Dim myMessageItem As Object
Dim myAttachmentItems As Object
Dim myJobnumber As String
Dim MyDrive As String
Dim Title As String
Set myolApp = CreateObject("Outlook.Application")
Set myMessageItem = Inspector.CurrentItem
Set myAttachmentItems = myMessageItem.Attachments
'Set objreply = myMessageItem.Reply
With myMessageItem
If .To = "" Then GoTo Getout
'If Not objreply = "" Then GoTo Getout
'basic info about message
Debug.Print .To
Debug.Print .CC
Debug.Print .Subject
Debug.Print .Body
If .UnRead Then
Debug.Print "Message has not been read"
Else
Debug.Print "Message has been read"
End If
myJobnumber = InputBox("Title prefix?", Title, "99999")
If myJobnumber = "" Then GoTo Getout
MyDrive = InputBox("What is the case number", Title, "Case Number")
MyDrive = "C:\" & MyDrive & "\1\"
If MyDrive = "" Then
Dim AbortRetryIgnore
AbortRetryIgnore = MsgBox("Not a valid case number - Retry or Cancel?", vbRetryCancel + vbCritical)
Select Case AbortRetryIgnore
Case vbRetry
MyDrive = InputBox("What is the case number", Title, "Case Number")
Case vbCancel
GoTo Getout
End Select
End If
If Dir(MyDrive, vbDirectory) = "" Then
MsgBox "No such Customer!"
GoTo Getout
End If
.SaveAs MyDrive & myJobnumber & "-" & myMessageItem & ".txt", olTXT
End With
DoEvents
'start of attachment process
For Each myMessageItem In myAttachmentItems
myJobnumber = InputBox("Title prefix?", Title, "99999")
If myJobnumber = "" Then GoTo Getout
MyDrive = InputBox("What is the case number", Title, "Case Number")
MyDrive = "C:\" & MyDrive & "\1\"
If MyDrive = "" Then
'Dim AbortRetryIgnore
AbortRetryIgnore = MsgBox("Not a valid case number - Retry or Cancel?", vbRetryCancel + vbCritical)
Select Case AbortRetryIgnore
Case vbRetry
MyDrive = InputBox("What is the case number", Title, "Case Number")
Case vbCancel
GoTo Getout
End Select
'If Dir(MyDrive, vbDirectory) = "" Then
'MkDir MyDrive
End If
'myMessageItem.SaveAsFile MyDrive & myJobnumber & "-" & myMessageItem.DisplayName
If Dir(MyDrive, vbDirectory) = "" Then
MsgBox "No such Customer!"
GoTo Getout
End If
myMessageItem.SaveAsFile MyDrive & myJobnumber & "-" & myMessageItem.DisplayName
Next
Getout:
Set myolApp = Nothing
Set myMessageItem = Nothing
Set myAttachmentItems = Nothing
End Sub
# re: Getting a Handle on Your E-mails with VBA 1/14/2005 7:58 AM
Sorry to cut in the middle of the thread but wanted to post my thanks.
Thanks for the help Eric!
# re: Getting a Handle on Your E-mails with VBA 1/14/2005 8:25 AM
VilMarci: Try this code that demonstrates how to automate sending an e-mail from an external application, where you are not working with code in an Outlook VBA Project. Just adapt it for your needs:
Option Explicit
Dim WithEvents objMailItem As Outlook.MailItem
Dim blnSent As Boolean
Private Sub Command1_Click()
Dim objOL As Outlook.Application
Set objOL = New Outlook.Application
Set objMailItem = objOL.CreateItem(olMailItem)
objMailItem.Subject = "Test"
objMailItem.Display True 'No further code will run until the message is closed/sent
If blnSent = True Then
'At this point, you can't work with the objMailItem Object any further
MsgBox "The e-mail has been sent!"
blnSent = False
End If
Set objMailItem = Nothing
Set objOL = Nothing
End Sub
Private Sub objMailItem_Close(Cancel As Boolean)
'Will be called after the Send event
'you can't work with the objMailItem Object here either
End Sub
Private Sub objMailItem_Send(Cancel As Boolean)
blnSent = True
MsgBox "Sending the e-mail message..."
End Sub
# re: Getting a Handle on Your E-mails with VBA 1/14/2005 8:53 AM
Nick: Try this adaptation of the clsMailItemTrapper class with your code implemented; I've made same changes with comments to help you understand why I did what I did.
However, you may want to rethink whether your custom process is suited to run while an e-mail is being opened. Perhaps it should be run when a user clicks a custom button, before the message is closed, etc. Just move the code in the Open event to another location as required.
Option Explicit
Dim WithEvents colInspectors As Outlook.Inspectors
Dim WithEvents objInspector As Outlook.Inspector
Dim WithEvents objMailItem As Outlook.MailItem
Private Sub Class_Initialize()
Set colInspectors = Application.Inspectors
End Sub
Private Sub Class_Terminate()
Set objMailItem = Nothing
Set colInspectors = Nothing
Set objInspector = Nothing
End Sub
Private Sub colInspectors_NewInspector(ByVal Inspector As Inspector)
Select Case Inspector.CurrentItem.Class
Case olMail
Set objMailItem = Inspector.CurrentItem
Set objInspector = Inspector
Case Else
'We only want to work with MailItem objects
Exit Sub
End Select
'Moved everything to the objMailItem_Open event
End Sub
Private Sub objInspector_Close()
'Dereference objMailItem when the container closes
Set objMailItem = Nothing
End Sub
Private Sub objMailItem_Open(Cancel As Boolean)
'Dim myolApp As Object 'Not needed; Outlook.Application is an intrinsic object inside an Outlook VBA Project
'Dim myMessageItem As Object 'Not needed: already declared as objMailItem in the module
Dim myAttachmentItems As Outlook.Attachments 'Object; changed to use early binding
Dim myJobnumber As String
Dim MyDrive As String
Dim Title As String
'Set myolApp = CreateObject("Outlook.Application") 'Don't need
'Set myMessageItem = Inspector.CurrentItem
'We will replace myMessageItem with objMailItem
'Set myAttachmentItems = myMessageItem.Attachments
'Replace with existing variable
Set myAttachmentItems = objMailItem.Attachments
With objMailItem
If .To = "" Then GoTo Getout
'basic info about message
Debug.Print .To
Debug.Print .CC
Debug.Print .Subject
Debug.Print .Body
If .UnRead Then
Debug.Print "Message has not been read"
Else
Debug.Print "Message has been read"
End If
myJobnumber = InputBox("Title prefix?", Title, "99999")
If myJobnumber = "" Then GoTo Getout
MyDrive = InputBox("What is the case number", Title, "Case Number")
MyDrive = "C:\" & MyDrive & "\1\"
If MyDrive = "" Then
Dim AbortRetryIgnore As Long 'Must declare variable type with Option Explicit
AbortRetryIgnore = MsgBox("Not a valid case number - Retry or Cancel?", vbRetryCancel + vbCritical)
Select Case AbortRetryIgnore
Case vbRetry
MyDrive = InputBox("What is the case number", Title, "Case Number")
Case vbCancel
GoTo Getout
End Select
End If
If Dir(MyDrive, vbDirectory) = "" Then
MsgBox "No such Customer!"
GoTo Getout
End If
.SaveAs MyDrive & myJobnumber & "-" & objMailItem.Subject & ".txt", olTXT
End With
'DoEvents ;Not needed
'start of attachment process
'For Each myMessageItem In myAttachmentItems
'myMessageItem is now explicitly declared as a MailItem object; we need a new variable for this
Dim myAtt As Outlook.Attachment
For Each myAtt In myAttachmentItems
myJobnumber = InputBox("Title prefix?", Title, "99999")
If myJobnumber = "" Then GoTo Getout
MyDrive = InputBox("What is the case number", Title, "Case Number")
MyDrive = "C:\" & MyDrive & "\1\"
If MyDrive = "" Then
AbortRetryIgnore = MsgBox("Not a valid case number - Retry or Cancel?", vbRetryCancel + vbCritical)
Select Case AbortRetryIgnore
Case vbRetry
MyDrive = InputBox("What is the case number", Title, "Case Number")
Case vbCancel
GoTo Getout
End Select
End If
If Dir(MyDrive, vbDirectory) = "" Then
MsgBox "No such Customer!"
GoTo Getout
End If
myAtt.SaveAsFile MyDrive & myJobnumber & "-" & myAtt.DisplayName
Next
Getout:
'Cleanup
Set myAttachmentItems = Nothing
Set myAtt = Nothing
End Sub
# re: Getting a Handle on Your E-mails with VBA 1/18/2005 9:06 AM
wow eric that is great.
thank you for having a look at it!
really saving my bacon.
two things if you have a little more time - then i think i may be an outlook guru!! well we can hope anyway!
how can i recogise whether someone presses reply on the e-mail as it activates my code and i dont want it too!!
i managed to recognise a forward as the to: field would be blank.
i tried using this and stopping script but i cant get it to run.
Private Sub myItem_Reply(ByVal Response As Object, Cancel As Boolean)
lastly when i open a sent mail which has already been replied too and some point the code will not save the content of the e-mail as text.. i dont know why.. could it be because of the format of an e-mail which has been replied too... as it has lines in it separating each reply a particular e-mail has had?
sorry to keep bothering you but u are really helpful.
hopefully i can return the favour one day
# re: Getting a Handle on Your E-mails with VBA 1/18/2005 9:58 AM
Nick: the important object in my previous code sample is objMailItem. It is this mesasge that we are hooking into when the user opens ANY e-mail that gives us access to all of its events - when it opens, when it is replied to, when it is forwarded, etc.
To automate the message with your custom code/processes, trap the necessary events - in your case, objMailItem_Forward and objMailItem_Reply.
# re: Getting a Handle on Your E-mails with VBA 1/28/2005 10:32 AM
Hi
I have taken your advice and am going to add a button instead!
Everything is working fine but when i try and save the content of the e-mail when it has been previously replied to or forwarded it will save a blank file.
very odd!!!
# re: Getting a Handle on Your E-mails with VBA 2/8/2005 2:53 PM
quality. thanks
# re: Getting a Handle on Your E-mails with VBA 3/1/2005 6:16 AM
Hi,
Nice article to trap all the items
in an outlook folder.
But how to use same class file(clsMailItemTrapper) to trap an outlook item opened by clicking on the File Menu->Open Outlook Data file.
Thanks in advance
Regards
Champ
# re: Getting a Handle on Your E-mails with VBA 3/1/2005 8:19 AM
There are no events available to detect when a new .pst is added to the Data Files collection. However, my code above will handle ANY e-mail that is opened, regardless of where it is because it is trapping when Inspectors (message windows) are opened, which is really independent of the location of the message within the Inspector.
# re: Getting a Handle on Your E-mails with VBA 3/30/2005 8:17 PM
Hi Eric,
Office 2003 provides smart tag functionality to outlook if Word 2003 is the default email editor. Oulook uses InternetExplorer_Server
class window to show the messages composed using MS-Word or HTML
format and this window is capable of displaying smart tags. Messages
composed in Plain Text or Rich Edit are displayed in RichEdit20W
class window and this window cannot show smart tag information.
My problem is to provide smart tag kind of functionality to this
RichEdit20W class window. Is there any way to get the handle of
email viewer window of outlook?
One more behaviour I've observed that the smart tag information is
embeded into the message at the time of composing the message and
not at the time of viewing it. My requirement is to recognize smart
tags at the time of viewing the mails. I can choose any editor for
composing the message and any editor for viewing the message. I want
the smart tag functionality be available in every case.
Please help me if you have any idea in this regard.
- Rajeev
# re: Getting a Handle on Your E-mails with VBA 4/4/2005 9:51 AM
Rajeev: Good question! Are you trying to implement smart tags in e-mail messages that are being edited/displayed *without* Word Mail enabled? That is not possible, I know that much. I noticed that smart tags are enabled when Word Mail is on, regardless of the message format (Rich Text, HTML, Plain Text).
# re: Getting a Handle on Your E-mails with VBA 4/5/2005 3:12 AM
Eric, I am trying to implement smart tag *kind of* functionality for each mail message irrespective of Word Mail enabled. If Word Mail is on while editing the message you will get smart tag functionality as outlook will use Internet Explorer_Server class window to display the mesaage and it will not require any effort to see the smart tags. My problem is something different. I want to embed smart tag like functionality at the receiver end eg. after arrival of each new mail. The new mails can be edited using Word Mail on or off at the sender end. But the receiver of the mail should be able to see the smart tag in the mail. I wand to develop an addin which will embed this functionality on newmail event at receiver. I hope I am clear with my explaination. I know there is no documented and direct way available to achieve this. Any other idea or way if you have....
# re: Getting a Handle on Your E-mails with VBA 4/6/2005 8:22 AM
Rajeev: I understand what you want to do know. However, the Outlook Object Model doesn't provide the kind of hooks you need, especially in the message text area. Redemption (http://www.dimastry.com) provides some advanced text hooks via the SafeInspector object, but it still may not help you. You may need to develop your functionality using Extended MAPI with C++ (although I suspect you may have already started down that path).
# re: Getting a Handle on Your E-mails with VBA 4/15/2005 4:02 AM
'Person Name Smart Tag' functionality of Outlook provides the functionality to call or send mail to that person using smart tag menus with the help of windows messenger.
I want to do some preprocessing (like providing default message body or displaying a message box before placing call) on the click of these menu items using outlook automation or plug in. Is there any way to modify the name of these smart tag menu items and hooking or capturing the click
event of these menu items?
Please help me if you have any ideas in this regard. Let me know if I am not clear with my points.
# re: Getting a Handle on Your E-mails with VBA 4/15/2005 9:35 AM
Sachin: The Smart Tag interfaces are only exposed to Outlook when Word is used as the e-mail editor. For more info on Smart Tags, see these links:
A Developer's Take on Smart Tags (Microsoft Office 2003 Technical Articles):
http://msdn.microsoft.com/library/en-us/dno2k3ta/html/OfficeDevelopersTakeOnSmartTags.asp?frame=true
Welcome to the Smart Tag SDK -- Microsoft Office 2003 Smart Tag Software Development Kit (Microsoft Office 2003 Smart Tag Software Development Kit):
http://msdn.microsoft.com/library/en-us/stagsdk/html/stconWelcomeToSTagSDK_HV01074286.asp?frame=true
# re: Getting a Handle on Your E-mails with VBA 4/17/2005 11:59 PM
Eric: I am not talking about the smart tags available in the body of the mail, but the 'Person Name Smart Tags' available with To/From/Cc/Bcc e-mail addresses. If you move the mouse pointer to mail ids in these fields, a 'Windows Messenger' icon will appear and you can get a context menu by clicking on that icon. For this smart tag it is not required to use Word as the e-mail editor. I want to play with this smart tag. Please refer to my previous mail regarding my requirements....
# re: Getting a Handle on Your E-mails with VBA 4/18/2005 6:45 AM
Eric,
a very useful article. I am using the NewInspector event in a com add-in to capture when a user composes a new mail to open a custom vb form, the fields on this form will be used to generate the To, BCC and subject fields of the new email.
My understanding is that when the user clicks new mail it triggers the new
inspector, I'm using this event to test if the class of the current item is a
mail and then issuing a command to open my vb form (also checking to ensure this is not an existing mail). Logically this seems to be the right place to issue the command.
However what the user sees on the screen is my form loading first and then the new mail
form loading, as this event appears to occur after my form has loaded the new
mail obscures the vb form on the screen. As i need to use the information
entered on my vb form to compose the mail I need my form to have focus. I've
tried setting the focus to my form but this does not seem to work.
My other alternative was to use the inspector.close (oldiscard) to
automatically close the new mail form thus leaving my form visible and then
once the user had completed my vb form I would then create a new mail item
and set the 'subject' and 'BCC' fields using the information gathered from my
form this doesn't seem to work either.
Thanks in advance.
# re: Getting a Handle on Your E-mails with VBA 4/18/2005 8:29 AM
Sachin: Sorry, I lead you down the wrong path. We're not really talking about Smart Tags here, but the IM component. However, I'm not sure if you can extend the presence interface. If you can, it is not readily apparent (and you might need LCS), but consume this article in depth and let me know what you discover:
Real-time Communications (RTC) Client Start Page [RTC]:
http://msdn.microsoft.com/library/en-us/rtcclnt/rtc/real_time_communications_rtc_client_start_page.asp?frame=true
# re: Getting a Handle on Your E-mails with VBA 4/18/2005 8:41 AM
Paul: I *hate* this problem. I get around this by using a Timer class to wait about about a half second after the message opens, then I load my custom form.
There's a "form-free" timer you can use in this library:
vbAccelerator - Subclassing Without The Crashes:
http://www.vbaccelerator.com/home/VB/Code/Libraries/Subclassing/SSubTimer/article.asp
There are probably Win32API timer functions you can use as well, but the above works for me.
# re: Getting a Handle on Your E-mails with VBA 4/19/2005 10:39 AM
Hi,
nice code but found one issue with it while
using the clsMailItemTrapper class file.
If we open multiple messages from the INBOX,the clsMailItemTrapper file is trapping the Inspector close event(objOpenInspector) for the last opened outlook item only.
Please advice.
Thanks in advance
Regards
Champ
# re: Getting a Handle on Your E-mails with VBA 4/19/2005 10:54 AM
Champ: Yes, I know what you mean. To handle multiple Inspectors, you have to devise a wrapper collection to handle them individually. It is not much of a change - see the sample here:
Slovak Technical Services Code Samples:
http://www.slovaktech.com/code_samples.htm#InspectorWrapper
# re: Getting a Handle on Your E-mails with VBA 4/25/2005 4:53 AM
Hi there,
How to trap the mouse right click events on the already open outlook item ?
In Details:
1.Open an outlook item(having atthacments)
2.User selects one of the attachment of the mail.
3.Then he/she right clicks on the selected attachment and Choose "Save as" option from the popup menu.
I want to trap this "Save as" events.
Please advice.
Thanks in advance
Regards
Chaman Kedia
# re: Getting a Handle on Your E-mails with VBA 4/25/2005 2:54 PM
Chaman: Sorry, you can't drap mouse click events or attachment save events with the Outlook Object Model. You may be able to use Win32API calls to intercept mouse messages, but I don't know how to do it without doing some research.
# re: Getting a Handle on Your E-mails with VBA 6/14/2005 9:07 PM
I hope you can help me. I have this code that sends an email from Excel. However I can't tell if the code sent the email or if the user cancelled by way of closing the window. Do you know how I could test to see if the email was sent or not?
Thanks in advance for any help you can offer.
Michael
Code below:
Dim outApp As Object
Dim outmail As Object
Set outApp = CreateObject("Outlook.Application")
Set outmail = outApp.CreateItem(0)
With outmail
.To = "mjamici13@yahoo.com"
.CC = ""
.BCC = ""
.Subject = ""
.Body = ""
Attachments.Add CurrFile
.Attachments.Add ActiveWorkbook.FullName
.Display
'work around for the Outlook security warning message
Application.Wait (10)
SendKeys "^{Enter}", 5
End With
Set outmail = Nothing
Set outApp = Nothing
# re: Getting a Handle on Your E-mails with VBA 7/4/2005 9:58 AM
MJA: (sorry for the delay in replying, as I was on vacation) You could trap the Application_ItemSend event and compare the Item object that is passed to it with the variable you declared manually, or declare outmail as "Dim WithEvents outmail As Outlook.MailItem". The latter will allow you to trap the Send event; if it fires, your e-mail is about to send (it's highly unlikely it won't get sent at this point).
If you are saving sent messages to your Sent Items (or another folder), you could also set a MAPIFolder variable to that folder and search for the sent message as well.
# re: Getting a Handle on Your E-mails with VBA 7/7/2005 7:18 PM
Good article. I also need a super simple way to tell the difference between send and cancelled. When I use olmailitem.display (True) and press the send button, the display freezes until I press the close icon. I would like the display to exit after I press the send button. My users would otherwise be confused based on the current send operation of Outlook. Thanks for your help.
# re: Getting a Handle on Your E-mails with VBA 7/8/2005 10:45 AM
Ron: To determine whether the user has cancelled the message, you can probably set a module level variable to True during the Send event; thus, during Item_Close, if this is False, the Item_Send event never fired.
To alleviate the freezing problem, try Display(False) so that the form isn't modal.
# re: Getting a Handle on Your E-mails with VBA 7/12/2005 9:58 AM
I should have mentioned that I am using VBA from inside MS Access. How do I trap the OutLook events?
Dim objOutLook As Outlook.Application
Dim objOutLookMsg As Outlook.MailItem
Set objOutLook = CreateObject("Outlook.Application")
Set objOutLookMsg = objOutLook.CreateItem(olMailItem)
I could not find anything that equated to the ThisOutLookSession when searching through the OutLook Object Library.
Also after objOutLookMsg.To = Avalue, I can immediately read back that value however after objOutLookMsg.Body = Avalue, .Body is null unless I place a objOutLookMsg.Save before trying to read objOutLookMsg.Body.
Any reason for the difference? Thank you for your help.
# re: Getting a Handle on Your E-mails with VBA 7/12/2005 11:45 AM
If you are automating Outlook from an external application like Access, and you need to trap Outlook.Application events, you need to declare that object in the General Declarations section of a Module or Class Module like this:
Dim WithEvents objOutlook As Outlook.Application
This will expose the objOutlook variable to the list of objects that can be chosen in the objects drop down box, so you can create this stub:
Private Sub objOutlook_Startup()
End Sub
That's really the only difference as opposed to using the instrinsic Application object in ThisOutlookSession module within the Outlook VBA Editor.
As for the problems reading the .Body property, in what event are you reading it? If you set it during the Open event, the changes should be visible during the Send event without calling the Save method.
# re: Getting a Handle on Your E-mails with VBA 7/12/2005 3:54 PM
Eric, I am throughly confused by this code you previously cited. I tried to implement in MS Access VBA with no luck. Access will only allow WITHEVENTS in a Class module but if I put everything into the Class module, the subroutine is not visible even from the Immediate window (Function or subroutine not defined error msg).
In the VBAClass Module:
Option Compare Database
Option Explicit
Dim WithEvents objOutlookMsg As Outlook.MailItem
Dim boolSent As Boolean
Private Sub objOutlookMsg_Close(Cancel As Boolean)
MsgBox "OutlookMsg close"
End Sub
Private Sub objOutlookMsg_Send(Cancel As Boolean)
boolSent = True
MsgBox "sending mail"
End Sub
In the Utilities Module:
Option Compare Database
Option Explicit
Dim boolSent As Boolean
Sub SendThis()
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Set objOutlook = New Outlook.Application
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
objOutlookMsg.Subject = "Test"
' No further code will run until the message is closed/sent
objOutlookMsg.Display True
If boolSent = True Then
MsgBox "Mail sent"
boolSent = False
End If
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
The previous example impied that the clsMyMailItemTrapper class module was not necessary to trap events. I tried that and got a compile error message on the following statement:
Private Sub Class_Initialize()
==> Set objInspectors = Application.Inspectors
End Sub
Again I appreciate your assistance.
# re: Getting a Handle on Your E-mails with VBA 7/15/2005 7:19 PM
Great article! Works great! Thanks for taking it step-by-step.
# re: Getting a Handle on Your E-mails with VBA 7/17/2005 4:43 PM
Great Article, thanks.
Maybe you can give me a hint with the following problem:
I want appointments to be displayed immediatly in the calendar without having to open each appointment mail.
What I got now is a method that is triggered each time a mail comes in.
Thanks,
Carsten
# re: Getting a Handle on Your E-mails with VBA 7/19/2005 12:12 PM
Ron: Since Outlook's Application object is not exposed intrinsically in an Access project, you have to declare it explicitly in the General Declarations section of the Class Module:
Dim WithEvents objOutlook As Outlook.Application
In case you haven't already, also make sure to set a reference to the Microsoft Office Outlook X.0 Library.
# re: Getting a Handle on Your E-mails with VBA 7/22/2005 9:21 AM
Carsten: Try checking whether the incoming message is a Meeting Request item, then get a handle to it and call the Display and Close methods one after another. Maybe this will force the automatic creation of the Appointment item, but you'd probably see an annoying flash as the window opens and closes quickly.
# export? 8/4/2005 8:46 AM
Interesting article.
Does it exist an easy way to export a ThisOutlookSession/Class couple so that an unexperienced user can install it on his Outlook?
# re: Getting a Handle on Your E-mails with VBA 8/8/2005 9:11 PM
jumpjack: The easiest way is to export/import the modules in the VBA editor. See Distributing Microsoft Outlook VBA Code:
http://www.outlookcode.com/d/distributevba.htm.
# re: Getting a Handle on Your E-mails with VBA 8/24/2005 8:04 AM
'Person Name Smart Tags' are available with To/From/Cc/Bcc e-mail addresses of Outlook. If you move the mouse pointer to e-mail IDs in these fields, a 'Windows Messenger' icon will appear and you can get a context menu by clicking on that icon. This Smart Tag of Outlook provides the functionality to call or send mail to that person using smart tag menus by leveraging the functionality of 'Windows Messenger'.
I want to do some preprocessing (like providing default message body or displaying a message box before placing call) on the click of these menu items using outlook automation or plug in or any other possible way. Is there any way to modify the name of these smart tag menu items and hooking or capturing the click event of these menu items?
How Microsoft Outlook integrated with Windows messenger to provide call facility? Which DLL is responsible for it? Can I hook into that DLL to trap the click of Call menu?
AOL Instant messenger can be integarated to Outlook through one of its plugin called AIMSync. If you install this plugin you will see AIM icon along with Windows Messenger icon in To/From/Cc/Bcc e-mail addresses of Outlook. This is a kind of custom "Person Name Smart Tag" for AIM. Is there any way I can provide the same integration for my custom messenger as "Person Name Smart Tag" with my custom icom in To/From/Cc/Bcc e-mail addresses of Outlook?
Please help me if you have any ideas in this regard. Let me know if I am not clear with my points.
NB : I don’t want to do this activity via adding ‘Additional Actions’ in the smart tag menu, but I want to use the existing ‘Call Work..’ menu click event.
# re: Getting a Handle on Your E-mails with VBA 8/24/2005 8:36 AM
Rajeev: You need to use either the Smart Tag SDK or the Windows RTC Client API to do this, I'm not sure which. These links should help you determine the requirements for your solution:
Smart Tags and the Persona Menu:
http://msdn.microsoft.com/library/en-us/stagsdk/html/stconPersonaMenu_HV01082081.asp?frame=true
Integrating Windows Real-Time Communications into Applications (Windows XP Technical Articles):
http://msdn.microsoft.com/library/en-us/dnwxp/html/winrtcapplications.asp?frame=true
# re: Getting a Handle on Your E-mails with VBA 9/6/2005 4:59 AM
I am trying to retrieve the subject line from one particular e-mail address and forward the same subject line to other email address for all the e-mails received from that address. I m novice at vba. Can you help me with this?
Many thanks in advance
# re: Getting a Handle on Your E-mails with VBA 9/6/2005 5:05 AM
I am sorry, let me explain in detail. so I would like to capture the subject line from xyz@xyz.com in OL 2003 for all the new messages not the existing one and get the subject line of those messages and forward that subject line to abc@abc.com. This should be an ongoing process for all the emails receiving from xyx@xyx.com.
Many thanks in advance.
If anyone could get back to me with appropriate answer. my e-mail address is unifriend@msn.com.
# re: Getting a Handle on Your E-mails with VBA 9/9/2005 9:34 PM
Mohammed: If you want to trap incoming e-mails with VBA code, you have to hook into the ItemAdd for the Inbox folder. So your code will look something like this:
Dim myOlApp As New Outlook.Application
Public WithEvents myOlItems As Outlook.Items
Public Sub Initialize_handler()
Set myOlItems = myOlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub myOlItems_ItemAdd(ByVal Item As Object)
Dim myOlMItem As Outlook.MailItem
If Item.SenderEmailAddress <> "xyz@xyz.com" Then Exit Sub
'Forward message
Set myOlMItem = Item.Forward
myOlMItem.To = "abc@abc.com"
myOlMItem.Send
End Sub
# re: Getting a Handle on Your E-mails with VBA 9/14/2005 5:23 AM
Hi Eric,
Could you help me out.
I am looking to find out a way to when an email comes in from our server to report on backup success/failure, i need to take out from either the subject or body line whether the backup was successful or not and from what site/company.
Can this be done?
Thanks
Nick
# Thanks Eric 9/14/2005 7:04 AM
Thanks Eric, That should work for me.
# re: Getting a Handle on Your E-mails with VBA 9/14/2005 11:31 AM
Nick: See my response to the comment before yours for some sample code to get you started on automatically processing incoming e-mails. Once you have a hook into the message, you can read the MailItem.Body or MailItem.Subject properties to process the message further or extract what you need to evaluate. The InStr and Left/Right/Mid functions are the VBA functions to use for parsing String data.
# re: Outlook's Message Format Settings In The Registry 10/5/2005 10:42 AM
# re: Getting a Handle on Your E-mails with VBA 10/23/2005 7:03 AM
wish you you would actually show how DELETE your e-mails that pop Up when you get on your contact list!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!I'm NOT happy
# re: Getting a Handle on Your E-mails with VBA 10/23/2005 10:45 PM
"Delete e-mails that pop up when you get on your contact list"??? Could you explain your problem in more detail please?
# re: Getting a Handle on Your E-mails with VBA 10/28/2005 5:01 AM
Office2k sp3 exchng2003
Hey Eric
following problem i can't handle:
when creating a new message with the html-editor i want put in the first 2 lines
some html formatted text.
but objmail.htmlbody & "<b>test</b>"
doesn't work
it only works with the plain-text editor
how can i solve this ?
# re: Getting a Handle on Your E-mails with VBA 10/28/2005 9:13 AM
Andrew: I'm not sure what is going on in your situation. Can you please post more of your code? I know this works fine for me:
Sub Test()
Dim objItem As Outlook.MailItem
Set objItem = Application.CreateItem(olMailItem)
objItem.Display
objItem.BodyFormat = olFormatHTML
objItem.HTMLBody = "<b>test</b>"
Set objItem = Nothing
End Sub
# re: Getting a Handle on Your E-mails with VBA 11/3/2005 3:57 AM
Hey Eric
I always had the problem when opening the html-editor for a new message, that it didn't work. i work with redemption.safemailitem.
now, after hours of trying i finally found the reason : One Line at beginning of
objMailItem_Open - sub
SendKeys "^{Home}", true
helps to put the code in the editor
thanks for your help ..
# re: Getting a Handle on Your E-mails with VBA 11/4/2005 11:00 AM
I think I've tried the SendKeys approach in the past for putting the focus on the Message control, put had problems. It looks like the SafeInspector object exposes the hwnd for the control though - you may be able to use the Win32API to set the cursor inside.
# re: Getting a Handle on Your E-mails with VBA 11/28/2005 7:57 AM
Hi Eric,
Great Article. I've implemented these items and great for action trapping. I'm a newbie in the outlook environment and want to call the sub's you made in outlook from another application like Word or Excel. Now it just opens a new mailitem window but does not process the outlook vba script? Would you have any suggestions?
Thanks in advance
# re: Getting a Handle on Your E-mails with VBA 11/28/2005 9:08 AM
Erik: No, you cannot call code in the Outlook VBA project from Office or a custom application. However, you can code Outlook in much the same way within the other Office VBA editors by setting a reference to the Outlook Object Model:
Automating Outlook from other Microsoft Office applications:
http://msdn.microsoft.com/library/en-us/vbaol11/html/olconAutomatingOutlookFromOtherMicrosoftOfficeApplications_HV05273034.asp?frame=true
# re: Getting a Handle on Your E-mails with VBA 11/29/2005 7:33 AM
Hi,
I guess I am new learner to MSOutlook VBA coding. I dont know if this was covered but I have one slight issue to resolve.
Let me explain what I have done so far.
Someone sends out a email to somebody else but Bcc me. I try to reply-All. I put in the code to trap the reply-All event and give a message warning that I was Bcc.
If I say no then I am back to the original message in that it does not create the reply email note.
However, the issue is this. If I hit reply-All on the original message, then it ignores the warning.
Walking through the code in debug mode, I have an understanding that the listener is no longer my original message but the intended reply-all note that I previously tried to stop.
I was wondering how to get my listener to destroy the new item that came up with the warning and reset to the original mail. I dont even know if this is doable because I can think of many other ways to confuse the listener...unless...there is some way to close out the original email ( I dont like this idea but if this is the only work around then I guess its fine. )
If anyone has ideas, please drop in the suggestions. THanks,
================code========================
Private Sub objInspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
Dim objItem As Object
Set objItem = Inspector.CurrentItem
' If (objItem = objMail) Then
If objItem.MessageClass = "IPM.Note" Then
Set objMail = objItem
Set objInspector = Inspector
End If
' End If
End Sub
Private Sub objMail_ReplyAll(ByVal Response As Object, Cancel As Boolean)
If (objMail.SenderName = objMail.BCC) Or (objMail.SentOnBehalfOfName = objMail.BCC) Then
If MsgBox("Please be advised that '" & objMail.BCC & "' has been Bcc regarding this email matter." & vbCrLf & "Are you sure you want to do 'REPLY-ALL' to this e-mail?", 4) = 6 Then
Cancel = False
Else
Cancel = True
End If
End If
End Sub
=====================end====================
-Ikram
mikramuddin@gmail.com
# re: Getting a Handle on Your E-mails with VBA 12/5/2005 4:19 PM
My head hurts trying to understand your problem! I believe what is needed in this situation is an "Inspector Wrapper"; see http://www.slovaktech.com/code_samples.htm#InspectorWrapper.
Essentially, you add an new instance of each Inspector to this wrapper collection, which will allow you to individually access each e-mail as it's own entity. This will help you figure out which one you are working with and control them accordingly.
# re: Outlook's Message Format Settings In The Registry 2/16/2006 3:38 PM
# re: Getting a Handle on Your E-mails with VBA 3/26/2006 10:41 PM
You have called a refrence here for this object "clsMailItemTrapper" where do i get this from.
# re: Getting a Handle on Your E-mails with VBA 3/31/2006 12:33 PM
Dennis: The clsMailItemTrapper object is a Class Module that you have to create in the VBA Project, and populate it with the code that's outlined above.
# re: Getting a Handle on Your E-mails with VBA 4/5/2006 10:35 PM
As everyone have said, this is exactly what I was looking for. I am using your code to automatically turn plain text to rich text as you open emails and it works great.
There is one thing I've noticed: when I hit reply/replyall/forward without actually opening the email. It does not insert the original email info. It just starts off with the body of the previous email. So there is no separator. Is that normal? I am using Outlook 2003 with SP2 and rich text format. I am using your code to automatically turn plain text to rich text and it works great. Thanks in advance!
Here is what I modified in your code:
Private Sub objMailItem_Open(Cancel As Boolean)
' MsgBox "MailItem is opened..."
If objMailItem.BodyFormat = olFormatPlain Then
objMailItem.BodyFormat = olFormatRichText
objMailItem.Save
End If
End Sub
Below is what is missing from the email if I don't open first.
_____________________________________________
From: you
Sent: Wednesday, April 05, 2006 5:00 PM
To: xx
Cc: yy
Subject: RE: zz
# re: Getting a Handle on Your E-mails with VBA 4/10/2006 10:54 PM
Hi all,
I need add a VBA in my Outlook that download my new mails as .eml and extract the attachments to an specific folder.
I'm lost, can anyone help me ?
Thanks
Zephyr
# re: Getting a Handle on Your E-mails with VBA 4/17/2006 10:19 PM
Bill: I have no idea what could be happening there. It doesn't have anything to do with the message format conversion AFAIK.
# re: Getting a Handle on Your E-mails with VBA 4/17/2006 10:20 PM
Zephyr: .eml files can only be saved from Outlook Express. Are you using that version, or Outlook from the Office suite?
# re: Getting a Handle on Your E-mails with VBA 4/21/2006 5:20 PM
I'll bet you didn't anticipate thos degree of response when you posted this little diddy 18 months ago. Nice Article, good feedback to the responses. You are to be applauded for you patience, perserverance and knowledge of the subject.
Regards,
Sersoft
# re: Getting a Handle on Your E-mails with VBA 5/10/2006 9:50 PM
Hey Eric,
That's great for beginning who don't know the event sequence. In fact, this is the way to learn event sequence to put code into proper events.
I am going to present different layout for the same outlook form when viewed by the sender in the sent folder or the recipient in inbox (rules wizard may be active so it is not necessary in inbox)
The first thing that I am thinking of is who starts the outlook. I try to distinguish the sender and the recipient using the email but seems not a good solution as a user may send on behalf of another person.
There are 2 other approaches
1. save a copy of the message, move it to sent folder and sent another one with DeleteAfterSubmit is on.
2. attempt to change some properties after sent but got an exception
With the first option, it seems ok except the saved copy do not have a sent date/time. So the item appear at the buttom of the sent folder and the tracking is not available.
with the 2nd option, it return unknown exception in VB script.
Dim DummyVar
Function Item_Send
.
.
DummyVar="from the same process flow"
end function
Function Item_Close
If DummyVar="from the same process flow" then
' change some user properties here
end if
end function
I try to make the form self-contained (with VBScript) to ease deployment so I do not intend to build script for my sent folder or starts any VBA projects. Adding folder script to exchange is a huge corporate issues.
Do u have any good suggestion for that.
Regards,
Thomas
# re: Getting a Handle on Your E-mails with VBA 5/12/2006 11:07 AM
Thomas: I'm at a loss trying to understand exact what it is you are trying to do. Can you dumb it down for me please?
Also: Changing message properties during or after the Send event is generally a bad idea, as the item is usually locked down completely at this point.
# re: Getting a Handle on Your E-mails with VBA 6/8/2006 10:04 AM
Great job.. Thanks
# re: Getting a Handle on Your E-mails with VBA 6/25/2006 9:22 AM
Hey all,
I'm trying to do something that i thought to be simple but.... it was'nt.
i want to read the attachment in the memory (supose its a text file).
i've already got the Outlook.Attachment object, but cant seem to find a way to read its content withought saving it to the file system (wich is no good for me).
any help will be great, thanks.
# re: Getting a Handle on Your E-mails with VBA 6/26/2006 10:39 AM
Urubin: there is no way AFAIK to read the attachment without saving it to disk, unless you use Redemption (http://www.dimastr.com/redemption/).
# re: Getting a Handle on Your E-mails with VBA 7/1/2006 3:25 PM
Hello,
I have a recorded Macro that generates a form message but I need to edit it in the Visual Basics Application to copy the text from the subject line and past it into the body of the e-mail? Can someone help me with this?
Thank You,
# re: Getting a Handle on Your E-mails with VBA 7/5/2006 9:12 AM
Lesley-Anne: There are no clipboard functions available to you with the Outlook Object Model, but you can use MailItem.Subject to retrieve the subject text, and use MailItem.Body to set the message contents. Is that of any help?
# re: Getting a Handle on Your E-mails with VBA 7/19/2006 7:21 AM
Nice article, I'm using the "attachment warning" since months and it saved me from several embarassing no-attachment situations...
I'd like to implement a further feature: when double clicking on the attachment in a recevied mail, have Outlook saving the file in user-selected folder (rather than TEMP folder) and THEN opening it NOT in read-only mode.
Is this possible?
Using AttachmentRead event does not work, as attachment will be automatically TEMP-saved and opened AFTER execution of my code!
If not possible using events, can I implement a button which allows selecting attachments in current folder?
# re: Getting a Handle on Your E-mails with VBA 7/19/2006 7:22 AM
errata-corrige: I meant current MESSAGE, not current FOLDER:..
# re: Getting a Handle on Your E-mails with VBA 7/25/2006 6:33 AM
Thanks, Eric. This is very helpful. I've tried using the ReplyAll event, but instead of Cancel = True, I've added some code to remove all but the first recipient name if the user answers No. The code seems to run, and the MsgBox at the end shows that the recipients have all, except the first, been removed. The recipient count displays as 1. But ALL of the recipient names remain in the To field. (This was a reply that had three recipients in the To field.) Is this a bug with Outlook, or is there something else that I need to do?
My code (which replaces Cancel = True):
Dim i
Dim count As Integer
Dim msg As Outlook.MailItem
Set msg = ActiveInspector.CurrentItem
If msg.Recipients.count > 1 Then
count = msg.Recipients.count
For i = count To 2 Step -1
msg.Recipients.Remove i
Next i
End If
MsgBox msg.Recipients.count ' result = 1
# re: Getting a Handle on Your E-mails with VBA 8/3/2006 6:44 AM
I have success with the code with the warning for Reply to All (objMailItem_ReplyAll). That only fires when I choose Reply to All from an open mail item inspector. If I choose Reply to All from Explorer (my InBox - no message "open"), of course this code does not fire, as it's tied to the Inspector. Is there a way to fire similar code so that it traps Reply to All when we click that from an Explorer? Thanks, Richard
# re: Getting a Handle on Your E-mails with VBA 8/14/2006 10:10 AM
Lesley-Anne: Sounds like you just need a macro like this that you can run while the message is open:
ActiveInspector.CurrentItem.Body = ActiveInspector.CurrentItem.Body.Subject & vbCrLf & vbCrLf & ActiveInspector.CurrentItem.Body
This inserts the subject line into the beginning of the e-mail message.
# re: Getting a Handle on Your E-mails with VBA 8/14/2006 10:15 AM
Jumpjack: Since you can't cancel the AttachmentRead event, I don't see anything you can do in any meaningful way when the user is interacting with the list of attachments. Your best bet is to create a custom dialog (or list the attachments in a custom menu or combo box button) and trap their interaction with the control. Then you'll at least know which attachment file they are working with, and you can cache it to the file system and open it using ShellExecute.
# re: Getting a Handle on Your E-mails with VBA 8/14/2006 10:23 AM
Richard: This works fine for me, but I may have the code running in a different place than you. I have an Inspector wrapper class that is instantiated whenever a new MailItem is created. So if I open the original message and click Reply All, this event gets fired:
Private Sub myMsg_ReplyAll(ByVal Response As Object, Cancel As Boolean)
Dim objReply As Outlook.MailItem
Dim i
Dim count As Integer
Set objReply = Response
If objReply.Recipients.count > 1 Then
count = objReply.Recipients.count
For i = count To 2 Step -1
objReply.Recipients.Remove i
Next i
End If
MsgBox objReply.Recipients.count ' result = 1
Set objReply = Nothing
End Sub
Notice that I'm not using ActiveInspector. I suspect your code is working with the recipients of the *original* message, not the reply message.
# re: Getting a Handle on Your E-mails with VBA 8/16/2006 8:35 PM
Eric, this is a fantastic blog. Hats off to you for responding promptly to so many questions.
I'm trying to solve a problem that you might be able to help. Basically, I've some mails in my Inbox that are tagged with Followup flag so that these show up in "For Follow Up" folder. Now when I am reading a message in the "For Follow Up" folder, I'd like to click a button to jump to the same message but in the Inbox folder (I want this so that I can get back to other messages in conversation). In other words, go to Inbox but select the same message in Inbox.
Any ideas how to solve this? Thanks again.
# re: Getting a Handle on Your E-mails with VBA 8/18/2006 10:36 AM
mp: Unfortunately, there's no way to select one or more items in a folder with code. Your suggestion can be done in a roundabout way though, by creating or modifying a view in the Inbox to just show messages with the same subject line. However, working with Views requires some complex XML manipulation so I can't quickly come up with a macro for you. This approach may be overkill anyway!
# re: Getting a Handle on Your E-mails with VBA 10/4/2006 8:15 PM
hi, i've got a macro that reads addresses from an excel file and sends to all recepients in it. what i'd like to do is customize the message itself for each recepient.. possibly from the same excelshe