1

I'm writing a script that creates and updates an outlook note. Everything works fine except for one issue.

It creates and updates the note on my personal mailbox and I need it to create and maintain the note on a department mailbox that we all have access to(I have two accounts set up in my Outlook).

It is behaving this way despite the script being triggered by a rule on the department mailbox and being given mail items for the department mailbox. How do I tell VBS/Outlook which notes folder/account I want to use? I cannot find anything anywhere that outlines how to select which account the note will be created under.

I am using Outlook 2016.

Set olkFolder = Session.GetDefaultFolder(olFolderNotes)
Set olkNote = olkFolder.Items.Find("[Subject] = 'Sequential Number'")
If TypeName(olkNote) = "Nothing" Then
    Set olkNote = Application.CreateItem(olNoteItem)
    olkNote.Body = "Sequential Number" & vbCrLf & "NextValue=" & STARTING_VALUE + 1
    GetNextNumber = STARTING_VALUE
Else
    arrLines = Split(olkNote.Body, vbCrLf)
    For Each varLine In arrLines
        If Left(varLine, 10) = "NextValue=" Then
            GetNextNumber = CInt(Mid(varLine, 11))
            olkNote.Body = "Sequential Number" & vbCrLf & "NextValue=" & GetNextNumber + 1
        End If
    Next
End If
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
w00ten
  • 11
  • 2

2 Answers2

0

You can either move the note you created or add directly to the folder in the other account.

From the link, the code to Add:

Sub AddContact() 
    Dim myNamespace As Outlook.NameSpace 
    Dim myFolder As Outlook.Folder 
    Dim myItem As Outlook.ContactItem 
    Dim myOtherItem As Outlook.ContactItem 

    Set myNamespace = Application.GetNamespace("MAPI") 
    Set myFolder = myNamespace.GetDefaultFolder(olFolderContacts) 
    Set myOtherItem = myFolder.Items("Dan Wilson") 
    Set myItem = myFolder.Items.Add 
    myItem.CompanyName = myOtherItem.CompanyName 
    myItem.BusinessAddress = myOtherItem.BusinessAddress 
    myItem.BusinessTelephoneNumber = myOtherItem.BusinessTelephoneNumber 
    myItem.Display 
End Sub

If you have the mailbox in your navigation pane, "navigate down the tree". https://stackoverflow.com/a/6116820/1571407

ns.Folders("Personal Folders").Folders("Inbox")

In your code:

Set olkFolder = ns.Folders("name of other mailbox").Folders("Notes")

Whether the folder is in your navigation pane or not you may use CreateRecipient as described in the other answer.

Community
  • 1
  • 1
niton
  • 8,771
  • 21
  • 32
  • 52
0

Instead of using Application.CreateItem, either open the folder from another mailbox using Application.Session.CreateRecipient / Application.Session.GetSharedDefaultFolder and call MAPIFolder.Items.Add or (if the mailbox is already available in Outlook) drill down to that folder starting from Application.Session.Folders and (again) call MAPIFolder.Items.Add.

Replace

Set olkFolder = Session.GetDefaultFolder(olFolderNotes)
...
Set olkNote = Application.CreateItem(olNoteItem)

with

set recip = Session.CreateRecipient("SomeOtherUser@YourDomain.demo")
Set olkFolder = Session.GetSharedDefaultFolder(recip, olFolderNotes)
...
Set olkNote = olkFolder.Items.Add
Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • Could you maybe provide an example of how to use these? I'm not exactly a VBA or outlook expert so now I'm just more confused than before... It really should not be complicated to tell outlook "create a note in this mailbox's default notes folder". – w00ten Apr 07 '17 at 17:54
  • It is really not complicated. See the updated answer. – Dmitry Streblechenko Apr 07 '17 at 18:03
  • Is the mailbox containing this folder setup as an additional mailbox/account in Outlook, or do you only have delegate access to it? – Eric Legault Apr 09 '17 at 18:12
  • @Eric legault It is an actual mailbox/account in outlook. None of these solutions have worked for me despite running error free. I don't understand why it literally isn't as simple as `session.getdefaultfolder(account, olFolderNotes)` – w00ten Apr 10 '17 at 13:09
  • "Error free"? Can you actually step though your code one line at a time and see which line errors out or returns an unexpected value? – Dmitry Streblechenko Apr 10 '17 at 15:23
  • 1
    So then in addition to Dmitry's code, you need to loop through the NameSpace.Accounts collection until you find the Account object for the other mailbox. Then use Account.DeliveryStore to get a Store object, and use Store.GetDefaultFolder or Store.GetRootFolder to look for the Folder object you need. – Eric Legault Apr 10 '17 at 16:30
  • Really? Honestly, at this point it isn't worth it. I'll just map a drive and keep the needed data on a share. I've spent days and days on this. I didn't think accessing the notes folder on a second email account would be so ridiculously difficult(it shouldn't be) and the documentation from MS is trash, at best. I'm so frustrated I'm tempted to switch the whole company to Lotus Notes(yes, I do know how bad Lotus is)... Thanks for the help guys, you did what you could. – w00ten Apr 10 '17 at 17:31