Hi, Outlook new Mail item

Hello *,

I have two questions that I can't figgure out....

I have the following code (very simplified):

Set mailItem = CreateItem(Outlook.OlItemType.olMailItem)
mailItem.Body = "Some text..."
mailItem.Display (False)

Questions are:
1. How to change the status of the message so that when I close this new message I do not get window "Do you want to save changes "

2. How to insert autmaticly signature Now I parse signature files and add them as mailItem.Body = ...

I have Outlook 2003.

Thanks in advance,
Frenky



Answer this question

Hi, Outlook new Mail item

  • Lee-Shannon

    Hello FrenKy,

    1) Call the mail items close method passing in olDiscard (or 1)

    myItem.Close olDiscard

    2) Don't know, sorry.



  • Aquilegia

    Hi Derek!

    Thanks for reply, but you missed my point. Perhaps I was not clear when I wrote the question.

    What I want to do is to show "new mail" window using macro add few lines to the body and than have this window to type (by hand, not using macro) some mail aditional body in. I do not want to send the mail directly from macro, nor do I want to close it from macro. User should choose wether to close it or not.
    My goal is to create macro that will add some text (this has to be dynamic - thus macro, because I have to grab this text from one web page, and it has to be text, it can't be reference to that page...) and this is somewhat as a dynamic template/signature to be used when writing a mail.

    The problem is when I add something to the mail body from the macro, some property probably like "isModified" is changed. I do not know what is that property that is changed so I can't change it's status to something I want....

    As for automatic adding of signature, I came up with this:

    Private Function test(signatureName As String)
    Dim mailItem As Outlook.mailItem
    Dim allSignatures As CommandBarControls
    Dim allControls As CommandBarControls
    Dim i As Integer

    Set mailItem = CreateItem(Outlook.OlItemType.olMailItem)
    Set allControls = mailItem.GetInspector.CommandBars.Item("Insert").Controls

    For i = 1 To allControls.Count
    If allControls(i).Caption = "&Signature" Then
    Set allSignatures = allControls(i).Controls
    End If
    Next i

    For i = 1 To allSignatures.Count
    If allSignatures(i).Caption = signatureName Then
    allSignatures(i).Execute
    DoEvents
    End If
    Next i

    mailItem.Display (False)

    mailItem.Body = mailItem.Body & "Get some dinamyc text.."

    End Function

    Regards,
    FrenKy


  • Mark Leung

    I think you are right on this one...

    Regards,
    FrenKy


  • Ethan Hunt

    Hi again FrenKy,

    Ah ok... I think it uses the Saved property. If Saved is false when the message is closed then it prompts. Unfortunately Saved is a read only property. Which means you might need to save the new email as a draft, and thats not what your wanting to do.

    Your users might just have to grin and bear it. Not much of an expert with Outlook VBA so thats about all I know.



  • Hi, Outlook new Mail item