Consulting

Results 1 to 2 of 2

Thread: Outlook VBA - save message on send or pick up form send items

  1. #1
    VBAX Newbie
    Joined
    Sep 2014
    Posts
    1
    Location

    Outlook VBA - save message on send or pick up form send items

    Hi
    I have a macro that asks me if I wan to send an email without saving it to 'sent items' that's fine I added a bit of code to save the email to a C drive, it saves fine BUT when you open it from the c it thinks the message has not been sent.

    I tried another way by creating a separate VB script to compose and send the email then saving it but same tink.

    Is there a way to save a an email to c as a sent item or is there a way to identify the last email that has been sent and pick it out from the send items folder without having to write a script to loop through the send item folder ?

    Please see scripts below
    I would be grateful for any suggestions/assistance and would prefer to get the second method working but will be happy with either

    Outlook macro as described above
    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim intRes As Integer
    Dim strMsg As String
    Dim bullet
    Dim response
    bullet = Chr(10) & " " & Chr(149) & " "
    Do
    response = InputBox("Send options" & Chr(10) & bullet & "1.) Send - no keep" & bullet & "2.) Send - keep" & bullet & "0.) Quit" & Chr(10), "Send email options", 1)

    If IsNumeric(response) And response < 3 Then Exit Do 'Detect value response.
    MsgBox "You must enter a numeric value between 0 and 2.", 48, "Invalid Entry"
    Loop

    If response = 0 Then
    Cancel = True
    Else
    If Item.Class = olMail Then
    If response = 1 Then
    Item.DeleteAfterSubmit = True
    End If
    End If
    Item.SaveAs "C MySentMessage.msg"

    End If
    End Sub

    VB Macro as described above
    Set MyApp = CreateObject("Outlook.Application")
    Set MyItem = MyApp.CreateItem(0)
    Dim T_O
    call Recp
    With MyItem
    .To = T_O
    .Subject = "testSubject"
    .ReadReceiptRequested = False
    .HTMLBody = "Test"
    End With
    MyItem.Send
    MyItem.Display

    MyItem.SaveAs "C MySentMessage.msg"', olmsg

    Public suB Recp()
    T_O= "me at myemail. net"

    end Sub

  2. #2
    you could try specifically setting the sent property of the message to true before saving, or even possibly a doevents

    pick it out from the send items folder
    you could have a collection of items from the sent items folder withevents, when a new item is added to the collection, save it to c drive

    Dim T_O
    call Recp
    With MyItem
    .To = T_O
    i doubt this would actually populate the .to field of the message, maybe make Recp a function rather than a sub. else pass the variable by_ref
    Last edited by westconn1; 09-08-2014 at 05:07 AM.

Tags for this Thread

Posting Permissions

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