Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem displaying a newly created e-mail message

    I'm trying to write some simple code to create a new e-mail message, insert some text, then leave it on the screen for the user to edit and then send. I seem unable to get the message to stay on the screen when done.

    My code is as follows:

    <pre>Dim oOutlookApp As Application
    Dim Mail As MailItem
    Dim strMessage As String

    Set oOutlookApp = Application
    Set Mail = oOutlookApp.CreateItem(olMailItem)
    strMessage = "this is the message"

    With Mail
    .Subject = "Important e-mail"
    .To = "Everyone"
    .Body = strMessage
    .Display
    End With

    MsgBox "Send when ready."</pre>


    The problem is that when you click the message box away, the e-mail goes away, too. I need for it to stay.

    Ultimately, I need to use this code in WordPerfect, but as it currently is, when I run it from WP, not only does it not display at all (even briefly), when the macro is done, there is no sign of the e-mail ever having been created.

    Maybe there are other commands I can use to make it stay? Is there a Glue command? :-)

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Problem displaying a newly created e-mail message

    Try this? I changed your object call to the way I do it from inside Outlook, and I renamed Mail just in case there is a name conflict. I don't use .Display, but I think it's okay to do so.

    Dim oOutlookApp As Application
    Dim myMail As MailItem
    Dim strMessage As String
    Set oOutlookApp = GetObject(, "outlook.application")
    Set myMail = oOutlookApp.CreateItem(olMailItem)
    strMessage = "this is the message"

    With myMail
    .Subject = "Important e-mail"
    .To = "Everyone"
    .Body = strMessage
    .Display
    End With
    MsgBox "Send when ready."

    I have no idea whether this will work from outside Outlook.

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Problem displaying a newly created e-mail message

    Jefferson, thanks for the suggestion. Your code and my code seem to function the same. On closer look, it appears that the code is working fine, it was my method of testing that was flawed. I tested the code from the VBE, and when I clicked on OK in the message box, the e-mail message I created in the code disappeared. If I run the code from Outlook, the e-mail message is displayed when the message box is dismissed, which is what I want.

    Unfortunately, though, I can't get the e-mail message to be displayed when running the code from WordPerfect. I don't understand why it won't display, but I suppose I'll have to find another approach. My head is sore from banging it against the wall....

  4. #4
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Problem displaying a newly created e-mail message

    Hi Linda,
    I don't know if this will work (it may be a WP problem and I don't have it to test) but you could try moving the Mail.Display line after the msgbox line.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    2 Star Lounger
    Join Date
    Jan 2001
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Problem displaying a newly created e-mail message

    Rory, that was a great idea, but unfortunately, it didn't work. I can't imagine why WordPerfect can't display the message when the code works fine from within Outlook.

    I sincerely appreciate your suggestion!

  6. #6
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Problem displaying a newly created e-mail message

    Hi Linda,
    One other possibility: try adding oOutlookApp.visible = true
    (I can't remember what you called your application object so you might need to replace oOutlookApp). In case that doesn't work, I'll see if I can track down any info on differences between WP VB and Office VBA.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    2 Star Lounger
    Join Date
    Jan 2001
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Problem displaying a newly created e-mail message

    Rory, I wasn't able to get oOulookApp.visible = true to work in Outlook VBA. "Visible" does not appear to me to be an Application property. ???

    I am not using VBA in WordPerfect (I use PerfectScript, the "real" WP macro language), so the differences between the Outlook VBA and WP VBA won't help me.

    Thanks!

  8. #8
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Problem displaying a newly created e-mail message

    [img]/w3timages/icons/blush.gif[/img] my apologies Linda! I didn't actually check the Outlook object model - both Word and Excel's Application objects have a visible property and I just kind of assumed...
    I still can't figure why the email won't display if you put the .Display line after the msgbox line - have you tried oOutlookApp.ActiveInspector.Display to see if that works?
    Regards,
    Rory

    Microsoft MVP - Excel

  9. #9
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Problem displaying a newly created e-mail message

    Sorry to jump in on this...
    Do your users need to see the mail item before they get the message?
    i.e. - could you change the msg to 'Send the following message when ready' and have the OK invoke the mail item?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •