Reputation: 57
I'm in the process of converting some Outlook VBA \ Macros into add-ins. So far I'm not having a lot of luck piping this code over to VS2015 w\Office Dev Tools.
I've created a ribbon \ group \ buttons \ I can see it in Outlook and everything looks good but I'm receiving an error.
--ORIGINAL MACRO--
Sub Request()
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.Application.GetNamespace("MAPI")
Set objFolder = Session.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("Shared Documents")
Set myItem = objFolder.Items.Add("IPM.Note.Request")
myItem.Display
End Sub
I'm seeing that Set is no longer permitted so they've all been defined.
This particular line seems to be the problem. Session and\or GetDefaultFolder are returning Null and causing a runtime exception.
Error -- "System.NullReferenceException" --
objFolder = Session.GetDefaultFolder(olPublicFoldersAllPublicFolders).Folders("Shared Documents")
The suggestion from VS is to use the Sub "New" along with a few others that don't seem applicable.
A little help please. :-) Seems that I'm getting a mix of programming types mixed up from the VS error resolution suggestions.
Thank you. -Chris
Upvotes: 1
Views: 3679
Reputation: 57
Alrighty, it's working meow. Found this handy dandy webpage in case someone needs some pointers: https://support.microsoft.com/en-us/kb/313800
When you create a project for Outlook Add-ins it's being coded in VB.Net
Thank you DanL for the input, it got me thinking and searching again.
Private Sub Button1_Click(sender As Object, e As RibbonControlEventArgs) Handles Button1.Click
Dim objOutlook As Outlook._Application
objOutlook = New Outlook.Application()
Dim objNS As Outlook._NameSpace = objOutlook.Session
Dim objFolder As Outlook.MAPIFolder =
objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olPublicFoldersAllPublicFolders).Folders("Shared Documents")
Dim myItem = objFolder.Items.Add("IPM.Note.CustomFormName")
myItem.Display()
End Sub
Upvotes: 1