none
Class Module RRS feed

  • Question

  • Hi,

    I have this Class Module in my Outlook. I can't remember what it is for. I tried running it but I can't figure out how.

    How do I get this to run?

    Dim oMail As Outlook.MailItem
    Dim WithEvents noteInsp As Outlook.Inspector
    Dim oNote As Outlook.NoteItem
     
    Sub EditSelected()
    On Error GoTo EditSelected_Err
        Dim oInsp As Outlook.Inspector
        Dim oCBs As Office.CommandBars
     
        Set oMail = Application.ActiveExplorer.Selection.Item(1)
        Set oInsp = oMail.GetInspector
        oInsp.Display
        Set oCBs = oInsp.CommandBars
        oCBs.ExecuteMso "EditMessage" ' put it into edit mode
     
        Set oNote = Application.CreateItem(olNoteItem)
        Set noteInsp = oNote.GetInspector
        noteInsp.Display
       
    EditSelected_Exit:
    Exit Sub

    EditSelected_Err:
    MsgBox Err.Number & ", " & Err.Description
    Resume EditSelected_Exit

    End Sub
     
    Private Sub noteInsp_Close()
    On Error GoTo noteInsp_Close_Err
        Dim oAttach As Outlook.Attachment
     
        Set oAttach = oMail.Attachments.Add(oNote)
        oMail.Save
       
    noteInsp_Close_Exit:
    Exit Sub

    noteInsp_Close_Err:
    MsgBox Err.Number & ", " & Err.Description
    Resume noteInsp_Close_Exit

    End Sub

    Friday, February 10, 2012 3:58 PM

Answers

  • In the code you showed earlier when the note that's opened is closed it automatically attaches itself to the open mail item. Is that what you want? Is it working?
     
    If the code is running in the Outlook VBA project you do not want to use CreateObject() to get a handle to the Outlook.Application object. Use the intrinsic Application object, it's trusted by the object model security.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "mbrad" <=?utf-8?B?bWJyYWQ=?=> wrote in message news:f29d1b6d-38a4-4333-9afb-6a0b8ac400cc...

    Hi Ken,

    Yes, I was trying to run that one. I haden't thought of copying that macro to a regular macro. The code is currently under "Class Modules" and is called "ThisOutlookSession1"

    I copied it and ran it. Now I see what it is doing, and it's close to what I'm trying to accomplish.

    I have a user that asked me if it is possible to add a note to an email they received. The reason is that they have a string of emails that has ended with a reply of "Call Me". they then have a phone conversation, but no record of what was discussed. The logical place to put the info is in the email thread. If there was a way to attach the note to the selected email message we would have a solution.

    I also have this code which opens a note and puts the entered text into the note.

    Now I just need to tie the two together which I think I can do, but I just don't know how to attach the newly created note to the selected email. any thoughts?

    Thanks,
    Brad

    My other code run from UserForm4:

    Private Sub CommandButton1_Click()
    On Error GoTo StartOutLook_Error
    Dim spObj As Object, MyItem As Object
    Dim TheEmail As MailItem

    Set TheEmail = Application.ActiveExplorer.Selection(1)

     

              'Create a Microsoft OutLook object.
             Set spObj = CreateObject("Outlook.Application")

             ' Create and open new contact form for input.
             ' You can substitute olAppointmentItem, olJournalItem, olMailItem,
             ' olNoteItem, olPostItem, or olTaskItem for olContactItem.
              Set MyItem = spObj.CreateItem(olNoteItem)
              MyItem.Body = UserForm4.TextBox1
              UserForm4.Hide
              MyItem.Display

             ' Quit Microsoft Outlook.
              Set spObj = Nothing
              Exit Sub

    StartOutLook_Error:
             MsgBox "Error: " & Err & " " & Error
             Exit Sub
    End Sub


    Ken Slovak MVP - Outlook
    Friday, February 10, 2012 8:32 PM
    Moderator

All replies

  • Click in the procedure and press F5 to run the macro.
     
    The first macro will get the selected item and open it and put it in edit mode. It will also open a Note. The second macro attaches the note to the email.
     
    As it uses the Inspector ribbon it will require Outlook 2007 or later.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "mbrad" <=?utf-8?B?bWJyYWQ=?=> wrote in message news:7daea136-81bb-4bb0-8390-748ab6b17949...

    Hi,

    I have this Class Module in my Outlook. I can't remember what it is for. I tried running it but I can't figure out how.

    How do I get this to run?

    Dim oMail As Outlook.MailItem
    Dim WithEvents noteInsp As Outlook.Inspector
    Dim oNote As Outlook.NoteItem
     
    Sub EditSelected()
    On Error GoTo EditSelected_Err
        Dim oInsp As Outlook.Inspector
        Dim oCBs As Office.CommandBars
     
        Set oMail = Application.ActiveExplorer.Selection.Item(1)
        Set oInsp = oMail.GetInspector
        oInsp.Display
        Set oCBs = oInsp.CommandBars
        oCBs.ExecuteMso "EditMessage" ' put it into edit mode
     
        Set oNote = Application.CreateItem(olNoteItem)
        Set noteInsp = oNote.GetInspector
        noteInsp.Display
       
    EditSelected_Exit:
    Exit Sub

    EditSelected_Err:
    MsgBox Err.Number & ", " & Err.Description
    Resume EditSelected_Exit

    End Sub
     
    Private Sub noteInsp_Close()
    On Error GoTo noteInsp_Close_Err
        Dim oAttach As Outlook.Attachment
     
        Set oAttach = oMail.Attachments.Add(oNote)
        oMail.Save
       
    noteInsp_Close_Exit:
    Exit Sub

    noteInsp_Close_Err:
    MsgBox Err.Number & ", " & Err.Description
    Resume noteInsp_Close_Exit

    End Sub


    Ken Slovak MVP - Outlook
    Friday, February 10, 2012 4:31 PM
    Moderator
  • Thanks for the reply Ken.

    I pressed F5 and then the Macro window popped up wanting me to select which macro to run. Neither of these are listed in that window. All my other macros are though.

    I tried making a macro to all the ones posted above, but that didn't work either.

    Brad

    Friday, February 10, 2012 4:35 PM
  • Private Sub noteInsp_Close() isn't a macro actually, it's an event handler for the Inspector.Close() event. So you can't call that as a macro. The Sub EditSelected() procedure is a macro however and should show up in the macro list.

    Is the code in a class or a code module? If it's in a class, which I suspect as it has an event handler you couldn't call it directly, you'd have to instantiate an instance of the class and call it as a class level sub. Why not try putting the code in the ThisOutlookSession class? That way you can call the macro and the event would fire.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "mbrad" <=?utf-8?B?bWJyYWQ=?=> wrote in message news:e73f0472-2f93-436f-930b-a00b20e6c7e2...

    Thanks for the reply Ken.

    I pressed F5 and then the Macro window popped up wanting me to select which macro to run. Neither of these are listed in that window. All my other macros are though.

    I tried making a macro to all the ones posted above, but that didn't work either.

    Brad


    Ken Slovak MVP - Outlook
    Friday, February 10, 2012 4:41 PM
    Moderator
  • Hi Ken,

    Yes, I was trying to run that one. I haden't thought of copying that macro to a regular macro. The code is currently under "Class Modules" and is called "ThisOutlookSession1"

    I copied it and ran it. Now I see what it is doing, and it's close to what I'm trying to accomplish.

    I have a user that asked me if it is possible to add a note to an email they received. The reason is that they have a string of emails that has ended with a reply of "Call Me". they then have a phone conversation, but no record of what was discussed. The logical place to put the info is in the email thread. If there was a way to attach the note to the selected email message we would have a solution.

    I also have this code which opens a note and puts the entered text into the note.

    Now I just need to tie the two together which I think I can do, but I just don't know how to attach the newly created note to the selected email. any thoughts?

    Thanks,
    Brad

    My other code run from UserForm4:

    Private Sub CommandButton1_Click()
    On Error GoTo StartOutLook_Error
    Dim spObj As Object, MyItem As Object
    Dim TheEmail As MailItem

    Set TheEmail = Application.ActiveExplorer.Selection(1)

     

              'Create a Microsoft OutLook object.
             Set spObj = CreateObject("Outlook.Application")

             ' Create and open new contact form for input.
             ' You can substitute olAppointmentItem, olJournalItem, olMailItem,
             ' olNoteItem, olPostItem, or olTaskItem for olContactItem.
              Set MyItem = spObj.CreateItem(olNoteItem)
              MyItem.Body = UserForm4.TextBox1
              UserForm4.Hide
              MyItem.Display

             ' Quit Microsoft Outlook.
              Set spObj = Nothing
              Exit Sub

    StartOutLook_Error:
             MsgBox "Error: " & Err & " " & Error
             Exit Sub
    End Sub

    Friday, February 10, 2012 4:53 PM
  • In the code you showed earlier when the note that's opened is closed it automatically attaches itself to the open mail item. Is that what you want? Is it working?
     
    If the code is running in the Outlook VBA project you do not want to use CreateObject() to get a handle to the Outlook.Application object. Use the intrinsic Application object, it's trusted by the object model security.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "mbrad" <=?utf-8?B?bWJyYWQ=?=> wrote in message news:f29d1b6d-38a4-4333-9afb-6a0b8ac400cc...

    Hi Ken,

    Yes, I was trying to run that one. I haden't thought of copying that macro to a regular macro. The code is currently under "Class Modules" and is called "ThisOutlookSession1"

    I copied it and ran it. Now I see what it is doing, and it's close to what I'm trying to accomplish.

    I have a user that asked me if it is possible to add a note to an email they received. The reason is that they have a string of emails that has ended with a reply of "Call Me". they then have a phone conversation, but no record of what was discussed. The logical place to put the info is in the email thread. If there was a way to attach the note to the selected email message we would have a solution.

    I also have this code which opens a note and puts the entered text into the note.

    Now I just need to tie the two together which I think I can do, but I just don't know how to attach the newly created note to the selected email. any thoughts?

    Thanks,
    Brad

    My other code run from UserForm4:

    Private Sub CommandButton1_Click()
    On Error GoTo StartOutLook_Error
    Dim spObj As Object, MyItem As Object
    Dim TheEmail As MailItem

    Set TheEmail = Application.ActiveExplorer.Selection(1)

     

              'Create a Microsoft OutLook object.
             Set spObj = CreateObject("Outlook.Application")

             ' Create and open new contact form for input.
             ' You can substitute olAppointmentItem, olJournalItem, olMailItem,
             ' olNoteItem, olPostItem, or olTaskItem for olContactItem.
              Set MyItem = spObj.CreateItem(olNoteItem)
              MyItem.Body = UserForm4.TextBox1
              UserForm4.Hide
              MyItem.Display

             ' Quit Microsoft Outlook.
              Set spObj = Nothing
              Exit Sub

    StartOutLook_Error:
             MsgBox "Error: " & Err & " " & Error
             Exit Sub
    End Sub


    Ken Slovak MVP - Outlook
    Friday, February 10, 2012 8:32 PM
    Moderator