I have some vba code to move all emails from an outlook 2016 folder to OneNote 2016, which runs without errors, but it effectively does nothing. I'm not sure what is wrong.
OneNote is set to automatically send print/receive requests to a certain area and when I click the "Send To OneNote" button manually in emails, it works fine. I have this set so the dialogue box doesn't interrupt the macro from simply cycling through all of the emails. There's also nothing else in the onenote. I've stepped through the code (F8), and the if/then works, e.g. it goes to the then. It basically seems like the .commandbars.executemso line just doesn't execute?
Public Sub Send21Note()
Dim item as Outlook.mailitem, Buck as Outlook.items, NS as NameSpace
Set NS = Application.GetNamespace("MAPI") ' This is intended to be run manually with ol already open
Set Buck = NS.Sessions.folder("TargetFolder").items
For each item in Buck
With item.getinspector
If .commandbars.getenabledmso("MoveToOnenote") then .commandbars.executemso ("MoveToOneNote")
.close oldiscard
end with
next
end sub
Any help would be appreciated.
I've already scoured google/SO, and I couldn't find relevant threads to this issue (e.g. .executemso simply not executing). I explored other options (e.g. trying to use a clipboard/richtextformat converter), but the result so far has been lackluster. Attachments get lost, not all of the formatting can be retained, and unfortunately some of these emails contain pictures which also get lost via other methods.
I have explored the XML side of things to reach into OneNote as well, but I've not been proficient and successful with this yet. I don't think this route is a priority because mapping into OneNote would allow for things like naming the pages, etc., but those are luxury element. The core task is basically exporting the email content to onenote, which should be achievable within VBA from what I gather.