Ask a questionAsk a question
 

QuestionMacro userform help... simple I'm sure

  • Wednesday, October 28, 2009 7:52 AMJsmaltz Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Little new to VBA so bear with me...


    Keep getting error 440 when clicking my command button, code is:

    Private Sub CommandButton1_Click()
        Dim OLitem As Outlook.MailItem
       
        Set OLitem = Application.CreateItem(olMailItem)
        With OLitem
            .Subject = "Something"
            .Body = "This is a sample message."
        End With
        OLitem.Display
    End Sub

    This is in my userform code... when i place this in module code it runs fine as a single macro... But I need the userform because it includes all the options, simple for use... Somewhere down the line I think I confused myself and missed something... HELP!!!

All Replies

  • Wednesday, October 28, 2009 8:37 AMJsmaltz Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Keeps hanging up at the "OLitem.Display"
  • Wednesday, October 28, 2009 12:14 PMADG Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi, unless you are actually working in Outlook you need to change your code to the below:

    Private Sub CommandButton1_Click()
    Dim OLitem As Outlook.MailItem
    Dim olApp As Outlook.Application
       
        Set olApp = Outlook.Application
        Set OLitem = olApp.CreateItem(olMailItem)
        With OLitem
            .Subject = "Something"
            .Body = "This is a sample message."
        End With
        OLitem.Display

    End Sub

    If you are in Outlook perhaps its not hanging, but openning the email, but not as the current window.

    Regards

    ADG 

  • Thursday, October 29, 2009 5:35 AMJsmaltz Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I placed the code and it still did not execute...

    When I place either code alone in a macro it works fine and opens a new email etc, but when I set the macro to load the userform and place the code under a commandbutton, it gives an error dialog box:

    Run-time error '2147467259 (80004005)'

    A dialog box is open. Close it and try again.

    Outlook is already open and the macro is on the toolbar.
    Module 1 (code)

    sub email()
    Load userform3
    userform3.show
    end sub

    loads my menu fine

  • Tuesday, November 10, 2009 8:58 AMJsmaltz Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Any help?