Fumi
Posts: 12
Joined: 2020-12-12
|
In "AddinModule.vb", to reference Outlook object, I can simply call "OutlookApp" below (see #1 below).
Private Sub AdxRibbonButton1_OnClick(sender As Object, control As IRibbonControl, pressed As Boolean) Handles AdxRibbonButton1.OnClick
Dim olApp As Object = OutlookApp '#1
Dim olNameSpace As Outlook.NameSpace = olApp.GetNamespace("MAPI")
....
....
....
End Sub
But, I want to reference the same "OutlookApp" on another form (See #2), but it fails because it does not exist. Instead, I could create Outlook object (See #3), which seems to be working fine.
Private Sub AdxRibbonButton1_OnClick(sender As Object, control As IRibbonControl, pressed As Boolean) Handles AdxRibbonButton1.OnClick
Dim fmForm As New fmMain
fmForm.Show()
End Sub
Private Sub fmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Dim olApp As Object = OutlookApp <-- OutlookApp not available in "fmMain" object #2
Dim olApp As Object = CreateObject("Outlook.Application") '#3
Dim olNameSpace As Outlook.NameSpace = olApp.GetNamespace("MAPI")
....
....
....
End Sub
If I remember correctly, I read an article on your website that I should always reference to "OutlookApp" object, instead of creating a new Outlook object. Is that the correct understanding?
If so, what is the best way to reference "OutlookApp" on another form? Should I try to pass the object to the another form?
Thanks. |
|
Andrei Smolin
Add-in Express team
Posts: 18829
Joined: 2006-05-11
|
Hello Fumi,
Fumi writes:
Is that the correct understanding?
Yes.
Use this construct:
{add-in project name such as MyAddin1}.AddinModule.CurrentInstance.{property or method declared on the add-in module such as ExcelApp}
Andrei Smolin
Add-in Express Team Leader |
|
Fumi
Posts: 12
Joined: 2020-12-12
|
|
Andrei Smolin
Add-in Express team
Posts: 18829
Joined: 2006-05-11
|
You are welcome!
Andrei Smolin
Add-in Express Team Leader |
|