devin@lilliangroup.com-1
Posts: 39
Joined: 2015-11-20
|
I am making an outlook addin to override built-in keyboard shortcuts. In the main AddinModule.vb I would like to create module level objects that are reused by various functions so that I don't have the overhead of recreating them each time the user performs a keyboard shortcut, but I am getting an error when I try to build the project. Below is what I'm trying to accomplish, and I can do it in non addin express projects but cannot figure out how to do it here:
Imports System.Runtime.InteropServices
Imports System.ComponentModel
Imports System.Windows.Forms
Imports AddinExpress.MSO
Imports Word = Microsoft.Office.Interop.Word
Imports Outlook = Microsoft.Office.Interop.Outlook
'Add-in Express Add-in Module
<GuidAttribute("omitted for privacy"), ProgIdAttribute("MyAddin3.AddinModule")> _
Public Class AddinModule
Inherits AddinExpress.MSO.ADXAddinModule
'I have omitted the Add-in Express automatic code in this post but it does exist in the real module
Public ReadOnly Property OutlookApp() As Outlook._Application
Get
Return CType(HostApplication, Outlook._Application)
End Get
End Property
Private nsMapi As Outlook.NameSpace = OutlookApp.GetNamespace("MAPI")
Private fldLHPIC As Outlook.Folder = nsMapi.Folders("emailAddress@gmail.com").Folders("LHPIC")
Private Sub MoveToLHPIC()
Dim oMailItem As Outlook.MailItem = OutlookApp.ActiveInspector.CurrentItem
oMailItem.UnRead = False
oMailItem.Move(fldLHPIC)
End Sub
End Class
|
|
devin@lilliangroup.com-1
Posts: 39
Joined: 2015-11-20
|
SOLVED
What I had to do was declare the module level objects within the class but outside of any procedures but not assign anything to them. Then in the AddinModule_AddinStartupComplete event I assign their objects to them, see below for revised code. Hope it helps someone else with the same issue.
Imports System.Runtime.InteropServices
Imports System.ComponentModel
Imports System.Windows.Forms
Imports AddinExpress.MSO
Imports Word = Microsoft.Office.Interop.Word
Imports Outlook = Microsoft.Office.Interop.Outlook
'Add-in Express Add-in Module
<GuidAttribute("omitted for privacy"), ProgIdAttribute("MyAddin3.AddinModule")> _
Public Class AddinModule
Inherits AddinExpress.MSO.ADXAddinModule
'I have omitted the Add-in Express automatic code in this post but it does exist in the real module
Public ReadOnly Property OutlookApp() As Outlook._Application
Get
Return CType(HostApplication, Outlook._Application)
End Get
End Property
Private fldLHPIC As Outlook.Folder 'Don't assign an object yet or it will error when building
Private Sub AddinModule_AddinStartupComplete(sender As Object, e As System.EventArgs) Handles Me.AddinStartupComplete
Dim nsMapi As Outlook.NameSpace = OutlookApp.GetNamespace("MAPI")
Dim fldRoot As Outlook.Folder = nsMapi.Folders("emailAddress@gmail.com")
fldLHPIC = fldRoot.Folders("LHPIC")
End Sub
Private Sub MoveToLHPIC()
Dim oMailItem As Outlook.MailItem = OutlookApp.ActiveInspector.CurrentItem
oMailItem.UnRead = False
oMailItem.Move(fldLHPIC)
End Sub
End Class
|
|
Andrei Smolin
Add-in Express team
Posts: 18829
Joined: 2006-05-11
|
devin@lilliangroup.com-1 writes:
What I had to do was declare the module level objects within the class but outside of any procedures but not assign anything to them
That's correct.
Andrei Smolin
Add-in Express Team Leader |
|