Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DragDrop Outlook MailItem Late Binding

Status
Not open for further replies.

SgtJarrow

Programmer
Apr 12, 2002
2,937
US
I have a small problem I just can't seem to find an answer to. I have an application that needs to have the ability to drag and drop emails into it. Information from the email is going to be stored. I have a working test, minus late binding. We have three versions of Outlook currently being used in my company so I need late binding for this drag and drop process.

Below is my code from my test form. This is using early binding to Outlook 2007. I am looking for help in converting this to late binding. If you can help - and even if you have some good references you can give me to read and figure this out - thanks.

Code:
        Dim outlook As Outlook.Application = Nothing
        Dim mail As Outlook.MailItem = Nothing
        Try
            outlook = DirectCast(Microsoft.VisualBasic.Interaction.GetObject("", "Outlook.Application"), Outlook.Application)
            Dim explorer As Outlook.Explorer = outlook.ActiveExplorer
            mail = DirectCast(explorer.Selection.Item(1), Outlook.MailItem)
        Catch ex As Exception
            MessageBox.Show("Error - Mail Item Not Found!", "Not Found")
        End Try
        MessageBox.Show(mail.To.ToString, "To")
        MessageBox.Show(mail.Subject, "Subject")
        MessageBox.Show(mail.Body, "Body")

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB.NET Programmer
 
No one has a suggestion to my original post - [neutral].

That's okay then...here's another idea. Maybe someone can answer this as my web searching has not led me to a good answer either.

Instead of using Late Binding for this instance, I would like to know if it is possible to do some sort of Conditional Reference. Here's my scenario:

I have a form with several text boxes: FROM, TO, SUBJECT, BODY, etc....all from the parts of an email. The user can enter or copy/paste from their email the necessary information. On the form, I would like to include a textbox or label that indicates if the user has the ability to drag/drop an email. If the user does, they can drop an email onto the control and the form gets filled in for them.

For example, I have Outlook 2007 installed. My Early Binding code above allows me to drag/drop emails. Another user only has Outlook 2003. They have to copy/paste each part separately.

Is there any way to allow for this sort of Conditional References??? If so, how would I go about setting it up??? Just need some pointers...Thanks for any help you can give.

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB.NET Programmer
 
If you don't get an answer then it is likely most of us don't work with outlook much. I don't work with it at all. As to your second question if it will only work for 2007 then you need to check what version they have installed. I don't know with how you are binding if it will allow it, but if you can do Outlook.Version then you are fine. If not you are going to have to look in the registry for it. The following is code I found and modified for excel. I changed it here for Outlook. I don't remember where I got the original code.

Code:
    Public Shared Function VersionInstalled() As Integer
        'The subkey's string value we check is like 
        'Outlook.Application.<version>, i e Outlook.Application.10 

        'The subkey we are interested of is located under the 
        'HKEY_CLASSES_ROOT class.
        Const stOtl_SUBKEY As String = "\Outlook.Application\CurVer"

        Dim rkVersionKey As Microsoft.Win32.RegistryKey = Nothing
        Dim stVersion As String = String.Empty
        Dim stOtlVersion As String = String.Empty

        Dim iVersion As Integer = Nothing

        Try
            'Here we try to open the subkey.
            rkVersionKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(name:=stOtl_SUBKEY, _
                                                           writable:=False)

            'If it does not exist it means that Excel is not installed at all.
            If rkVersionKey Is Nothing Then
                iVersion = 0

                Return iVersion
            End If

            'OK, Outlook is installed let's find out which version is available.
            stOtlVersion = CStr(rkVersionKey.GetValue(name:=stVersion))

            Dim OutlookVersionInfo As String() = stOtlVersion.Split(".")

            Return OutlookVersionInfo(OutlookVersionInfo.Length - 1)
        Catch ex As Exception
            MsgBox(ex.ToString)
            Return Nothing
        Finally
            If Not rkVersionKey Is Nothing Then
                rkVersionKey.Close()
            End If
        End Try
    End Function


-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Oh and 2007 is version 12.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top