none
Outlook Macro RRS feed

  • Question

  • Below is the Code which I am using, however it's allowing me to insert a new attachment (using edit email Option ) in the last email which I received in my inbox. Still trying to find out how can I rectify this issue.

    Can you please help me with that

    Public WithEvents myItem As Outlook.MailItem
    Dim flag As Boolean

    Private Sub Application_ItemLoad(ByVal Item As Object)

    If Item.Class = olMail Then
            flag = False
            Set myItem = Item
        End If
    End Sub

    Private Sub myItem_AttachmentRead(ByVal Attachment As Attachment)
    flag = True
    End Sub

    Private Sub myItem_Write(Cancel As Boolean)
    If flag Then
    MsgBox "You are not allowed to save "
    Cancel = True
    myItem.Close olDiscard
    End If
    End Sub
    Public Sub Initalize_Handler()
    Const strCancelEvent = "Application-defined or object-defined error"
    Set myItem = Application.ActiveInspector.CurrentItem
    End Sub

    Private Sub myItem_AttachmentAdd(ByVal Attachment As Attachment)
    flag = False ' if I select true then it will not allow me to insert Document while replying or sending any new email. 
    End Sub

    Private Sub myItem_AttachmentRemove(ByVal Attachment As Attachment)
    flag = True
    End Sub

    Wednesday, July 11, 2018 5:06 PM

Answers

  • I guess, I got the answer. If I need any help on this surely, will reach out to you.

    Thank you so much for your help :)

    Thanks

    Ankit

    Thursday, July 12, 2018 11:20 AM

All replies

  • Hi Ankit,

    Thanks for visiting our forum. Then here we mainly focus on general issues about Outlook desktop client. Since your query is related to Outlook macro, I'll move your thread to the dedicated MSDN forum for Outlook for better response:

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=outlookdev

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Regards,

    Yuki Sun


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.


    Thursday, July 12, 2018 2:07 AM
  • Hello Ankit Singh Jadon,

    Could you please detail your need? Which operation are allowed? Which operation are not allowed?

    It seem you won't do any restriction while editing a mail which is not sent. However, you won't user to add/remove attachment while editing a mail which has been sent or received from others, Right?

    If so, will the operation on other field,such as subject, to, body..., be prevented while editing a "send" mail?

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, July 12, 2018 9:34 AM
  • Thank you so much Terry for looking into this.

    above mentioned code is working fine, it will not allow to delete or modification in the Received and sent emails' attachment. However, it's allowing to add new attachment in the sent or Received emails.

    If you use Flag = True in Private Sub myItem_AttachmentAdd(ByVal Attachment As Attachment) then It will not allow to add attachment in the sent or Received emails. Also, it will not allow to add any attachment while replying , forwarding and sending any email.

    Or can we disable Edit Message option under Actions using macro then all the purpose will be resolved.

    Thank you in Advance.

    Thursday, July 12, 2018 9:48 AM
  • Hello Ankit Singh Jadon,

    In your another thread, according to your description, it seems that what you need is to protect original data, right?

    In this situation, what you need should be the whole mail rather then only the attachments, right?

    If so, i think use a flag to check the mail is a sent mail or received mail maybe more helpful.

    Would you want to just protect the attachments?

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, July 12, 2018 10:07 AM
  • Terry, If we protect whole email then other option also will not work like recall and etc..

    that's the reason I was thinking if we can disable Edit Message option under Actions using macro then all the purpose will be resolved.

     
    Thursday, July 12, 2018 10:27 AM
  • I guess, I got the answer. If I need any help on this surely, will reach out to you.

    Thank you so much for your help :)

    Thanks

    Ankit

    Thursday, July 12, 2018 11:20 AM