Open olNoteItem Attachment

Status
Not open for further replies.

Emmy

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server 2013
Hi,

I've written some code which creates and then attaches a blank Note to an e-mail:

Code:
Sub AddNote()

Dim objExplorer As Explorer
Dim OutlookMsg  As MailItem
Dim objNote As Object

Set objExplorer = Outlook.Application.ActiveExplorer

If objExplorer.Selection.Count = 0 Then
    MsgBox "An e-mail needs to be selected"
    Exit Sub
Else
    Set OutlookMsg = objExplorer.Selection.Item(1)
End If

Set objNote = Outlook.Application.CreateItem(olNoteItem)

objNote.Save

OutlookMsg.Attachments.Add objNote

objNote.Delete

End Sub
This works exactly as I want with one bit missing - how do I open the attached note so it is ready for the user to add some text directly, without having to double click to open it?

I have done some Googling and found that Outlook will save copies of attachments in a temporary folder when you want to open it but when I tried this, the text I added to the opened note was not saved to the note attached to the e-mail. I am able to achieve this manually though - if I run the code above, open the note by double clicking, add some text, close the note and then re-open it - the text I added still remains in the note attached to the e-mail.

Any help on this would be much appreciated.

Thanks,

Emmy
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
If i change delete to display, it opens the note but the changes aren't saved to the message (they are saved to the note in the Notes folder) but a bigger problem is that outlook treats it as a message when i reopen it, unless i add something to the body before it's added as an attachment.


Set objNote = Outlook.Application.CreateItem(olNoteItem)
objNote.Body = Time
objNote.Save
OutlookMsg.Attachments.Add objNote
objNote.Delete


What you need to do is close the attachment then open it - that should allow you to edit it and save the changes. Or use an inputbox to get the note before it's saved.
 

Emmy

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server 2013
Hi Diane,

Thanks very much for looking at this for me.

What do you mean - when you say I need to close the attachment first? I don't see the attachment as open.

Thanks,

Emmy
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Sorry about that, i meant clear the object - which delete does - then reopen it using code. This should replicate the double click to open steps, which you said worked.

FWIW, when i double clicked to open and added text using 2016, the changed note was saved in notes but not in the attachment.
 

Emmy

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server 2013
Hi Diane,

How do I open the attachment though? The attached note doesn't seem to be stored in the Outlook temporary folder.

If I run my code and then double click on the attachment the note opens up like this (with my Inbox in the background) but if I check the temporary folder nothing is there.

View attachment 1830

I'm trying to add the double click to my code but as the attached note isn't in the temporary folder I'm not sure how.

If however I use
Code:
OutlookMsg.Attachments(1).SaveAsFile "C:\Users\ekav\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.Outlook\7Y0WQL3M\Note.msg"
to save the attachment in the temporary folder and then use ShellExecute to open it, the text I type into the note is not saved in the attachment but is in the note in the temporary folder.

It's super annoying as it's just the double click I'm trying to replicate as when I open the note by double clicking on it and type into the resulting note pop-up this text is stored/saved within the attachment when the note is closed.

Perhaps this isn't possible via VBA? In which case the user can just open the note manually by double clicking on it before typing in the text...

Thanks again for looking at this.

Emmy
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Because it's an outlook item, it's not stored in the temp folder. It may not be possible to open it using code - i'll look into it but not holding my breath.
 

Emmy

New Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server 2013
OK, thanks Diane. Not to worry and much appreciated.
 
Status
Not open for further replies.
Top