VB .NET Outlook Addin Questions

C

Chris W

Hi
I'm writing my first Outlook add-in using VB.NET (first time in VB as well) and I've run into a couple of issues with the just the most basic of functionality (primarily code from MSDN)

First, the OnBeginShutdown and OnDisconnect events do not appear to be firing, which is leaving the Outlook process running. I've implemented the apparent workaround of creating a Close handler for the Explorer.Close event, but that also does not appear to be getting hit

Second, and my main concern, is that the BeforeFolderSwitch Explorer event does not appear to be firing either? Perhaps I am doing something wrong. The addin *is* being loaded, so it's not something simple like that :

Thanks for any help you can provide

XP Pr
Outlook 2000 SP
Visual Studio .NET 200

Public Class Connec

Implements Extensibility.IDTExtensibility

Dim WithEvents m_btnConfig As CommandBarButto
Dim WithEvents m_olOutlook As Outlook.Applicatio
Dim WithEvents m_olExplorer As Outlook.ExplorerClas

Dim applicationObject as Objec
dim addInInstance as objec


Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdow
On Error Resume Nex

m_btnConfig.Delete(
m_btnConfig = Nothin
m_olExplorer = Nothin
m_olOutlook = Nothin
End Su

Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnAddInsUpdat

End Su

Public Sub OnStartupComplete(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnStartupComplet
Dim oCommandBars As CommandBar
Dim oStandardBar As CommandBa

On Error Resume Nex
' Set up a custom button on the "Standard" command bar
oCommandBars = applicationObject.CommandBar
If oCommandBars Is Nothing The
' Outlook has the CommandBars collection on the Explorer object
oCommandBars = applicationObject.ActiveExplorer.CommandBar
End I

oStandardBar = oCommandBars.Item("Standard"

m_btnConfig = oStandardBar.Controls.Item("Configure"
If m_btnConfig Is Nothing The

m_btnConfig = oStandardBar.Controls.Add(1
With m_btnConfi
.Caption = "Configure
.Style = MsoButtonStyle.msoButtonCaptio

' The following items are optional, but recommended.
' The Tag property lets you quickly find the control
' and helps MSO keep track of it when more tha
' one application window is visible. The property is require
' by some Office applications and should be provided

.Tag = "Configure

' The OnAction property is optional but recommended.
' It should be set to the ProgID of the add-in, so that i
' the add-in is not loaded when a user clicks the button
' MSO loads the add-in automatically and then raise
' the Click event for the add-in to handle.

.OnAction = "!<MyCOMAddin.Connect>

.Visible = Tru
End Wit
End I

' Display a simple message to show which application you started in
'MsgBox("Started in " & applicationObject.Name & "."

oStandardBar = Nothin
oCommandBars = Nothin
End Su

Public Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnectio
On Error Resume Nex
If RemoveMode <> Extensibility.ext_DisconnectMode.ext_dm_HostShutdown Then
Call OnBeginShutdown(custom

addInInstance = Nothin
applicationObject = Nothin
End Su

Public Sub OnConnection(ByVal application As Object, ByVal connectMode As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnConnectio
'MsgBox("On Connection In MyAddin")
applicationObject = application
addInInstance = addInInst


' If you aren't in startup, manually call OnStartupComplete.
If (connectMode <> Extensibility.ext_ConnectMode.ext_cm_Startup) Then _
Call OnStartupComplete(custom)
End Sub

Private Sub MyButton_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean) Handles MyButton.Click
MsgBox("Our CommandBar button was pressed!")
End Sub

Private Sub m_olExplorer_BeforeFolderSwitch(ByVal NewFolder As Object, ByRef Cancel As Boolean) _
Handles m_olExplorer.BeforeFolderSwitch
MsgBox("BeforeFolderSwitch")
End Sub

Private Sub m_olExplorer_FolderSwitch() Handles m_olExplorer.FolderSwitch
MsgBox("FolderSwitch")
End Sub

Sub m_olExplorer_Close()
m_olExplorer = Nothing
End Sub

End Class
 
K

Ken Slovak - [MVP - Outlook]

See if any of the information at
http://www.microeye.com/resources/res_outlookvsnet.htm helps.




Chris W said:
Hi,
I'm writing my first Outlook add-in using VB.NET (first time in VB as
well) and I've run into a couple of issues with the just the most basic of
functionality (primarily code from MSDN).
First, the OnBeginShutdown and OnDisconnect events do not appear to be
firing, which is leaving the Outlook process running. I've implemented the
apparent workaround of creating a Close handler for the Explorer.Close
event, but that also does not appear to be getting hit.
Second, and my main concern, is that the BeforeFolderSwitch Explorer event
does not appear to be firing either? Perhaps I am doing something wrong. The
addin *is* being loaded, so it's not something simple like that :)
Thanks for any help you can provide!

XP Pro
Outlook 2000 SP3
Visual Studio .NET 2003

Public Class Connect

Implements Extensibility.IDTExtensibility2

Dim WithEvents m_btnConfig As CommandBarButton
Dim WithEvents m_olOutlook As Outlook.Application
Dim WithEvents m_olExplorer As Outlook.ExplorerClass

Dim applicationObject as Object
dim addInInstance as object


Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdown
On Error Resume Next

m_btnConfig.Delete()
m_btnConfig = Nothing
m_olExplorer = Nothing
m_olOutlook = Nothing
End Sub

Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnAddInsUpdate
'
End Sub

Public Sub OnStartupComplete(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnStartupComplete
Dim oCommandBars As CommandBars
Dim oStandardBar As CommandBar

On Error Resume Next
' Set up a custom button on the "Standard" command bar.
oCommandBars = applicationObject.CommandBars
If oCommandBars Is Nothing Then
' Outlook has the CommandBars collection on the Explorer object.
oCommandBars = applicationObject.ActiveExplorer.CommandBars
End If

oStandardBar = oCommandBars.Item("Standard")

m_btnConfig = oStandardBar.Controls.Item("Configure")
If m_btnConfig Is Nothing Then

m_btnConfig = oStandardBar.Controls.Add(1)
With m_btnConfig
.Caption = "Configure"
.Style = MsoButtonStyle.msoButtonCaption

' The following items are optional, but recommended.
' The Tag property lets you quickly find the control
' and helps MSO keep track of it when more than
' one application window is visible. The property is required
' by some Office applications and should be provided.

.Tag = "Configure"

' The OnAction property is optional but recommended.
' It should be set to the ProgID of the add-in, so that if
' the add-in is not loaded when a user clicks the button,
' MSO loads the add-in automatically and then raises
' the Click event for the add-in to handle.

.OnAction = "!<MyCOMAddin.Connect>"

.Visible = True
End With
End If

' Display a simple message to show which application you started in.
'MsgBox("Started in " & applicationObject.Name & ".")


oStandardBar = Nothing
oCommandBars = Nothing
End Sub

Public Sub OnDisconnection(ByVal RemoveMode As
Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnDisconnection
On Error Resume Next
If RemoveMode <>
Extensibility.ext_DisconnectMode.ext_dm_HostShutdown Then _
Call OnBeginShutdown(custom)

addInInstance = Nothing
applicationObject = Nothing
End Sub

Public Sub OnConnection(ByVal application As Object, ByVal connectMode
As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As
System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
'MsgBox("On Connection In MyAddin")
applicationObject = application
addInInstance = addInInst


' If you aren't in startup, manually call OnStartupComplete.
If (connectMode <> Extensibility.ext_ConnectMode.ext_cm_Startup) Then _
Call OnStartupComplete(custom)
End Sub

Private Sub MyButton_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
Handles MyButton.Click
 
C

Chris W

Thank you for your reply, Ken

I've actually changed to VB 6.0 to avoid having to drag .NET around with me :) I've been practically living on both Micro Eye and Slipstick, I have your book, Randy's book, Thomas Rizzo's book all in front of me and I just can't seem to put it all together (hey, what do you expect from a Unix server developer who's out of his element?)

I'm using the template found on Micro Eye's site, and for some reason, although I'm not even trying to do anything but run as is, the code is not working. I'm quite sure this is some stupid error on my part, but I sat with a VB developer earlier today for an hour and we can't figure out why it's failing. This code is failing because the gBaseClass variable is not instantiated (all from same designer file - OutAddIn class is in a separate class module)

Private gBaseClass As New OutAddIn 'At file-level scope (?), first uncommented code after Option Explici
..
Private Sub AddinInstance_OnConnection(ByVal Application As Object,
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode,
ByVal AddInInst As Object, custom() As Variant
..
gBaseClass.InitHandler Application, AddInInst.ProgI

Thanks

----- Ken Slovak - [MVP - Outlook] wrote: ----

See if any of the information a
http://www.microeye.com/resources/res_outlookvsnet.htm helps

--
Ken Slova
[MVP - Outlook
http://www.slovaktech.co
Author: Absolute Beginner's Guide to Microsoft Office Outlook 200
Reminder Manager, Extended Reminders, Attachment Option
http://www.slovaktech.com/products.ht


Chris W said:
Hi
I'm writing my first Outlook add-in using VB.NET (first time in VB a
well) and I've run into a couple of issues with the just the most basic o
functionality (primarily code from MSDN)firing, which is leaving the Outlook process running. I've implemented th
apparent workaround of creating a Close handler for the Explorer.Clos
event, but that also does not appear to be getting hitdoes not appear to be firing either? Perhaps I am doing something wrong. Th
addin *is* being loaded, so it's not something simple like that :
 
K

Ken Slovak - [MVP - Outlook]

VB 6 is often a better choice for Outlook addins, especially if you have to
support multiple versions of Outlook.

I'm surprised you are having problems with a straight run of the ItemsCB
sample. Do you have a reference set to the appropriate Outlook library, have
at least a comment in each exposed event of IDTExtensibility2 and have made
sure your class module is actually named OutAddIn? The instancing property
for that class definition should be multiuse.

I'd set a breakpoint at the beginning of On_Connection and step the code and
see what if any errors are being thrown when you call
gBaseClass.InitHandler. That might give us a clue as to what the problem is.




Chris W said:
Thank you for your reply, Ken!

I've actually changed to VB 6.0 to avoid having to drag .NET around with
me :) I've been practically living on both Micro Eye and Slipstick, I have
your book, Randy's book, Thomas Rizzo's book all in front of me and I just
can't seem to put it all together (hey, what do you expect from a Unix
server developer who's out of his element?).
I'm using the template found on Micro Eye's site, and for some reason,
although I'm not even trying to do anything but run as is, the code is not
working. I'm quite sure this is some stupid error on my part, but I sat with
a VB developer earlier today for an hour and we can't figure out why it's
failing. This code is failing because the gBaseClass variable is not
instantiated (all from same designer file - OutAddIn class is in a separate
class module):
Private gBaseClass As New OutAddIn 'At file-level scope (?), first
uncommented code after Option Explicit
 
K

Ken Slovak - [MVP - Outlook]

Odd, I've never seen that one before. The project references look OK.

First I probably would try compiling the code and then seeing if the code
ran. Then if that didn't work I probably would try removing the existing
ItemsCB and downloading it again and then seeing if that worked. If all else
failed I might even uninstall and reinstall VB to see if that made a
difference or I would run it on another of my development machines and see
if it worked there. That's all I can think of at the moment.




Chris W said:
Thanks for sticking with me, Ken...I appreciate it. Not used to being a newbie...

Short answer: thrown runtime error is Library not registered at the
gBaseClass.InitHandler call (will not step into InitHandler).
Detail:

All IDT2 interfaces are stubbed out with at least a comment, OutAddIn
module is indeed set to multiuse. References are set to:
VBA, runtime objects and procs, objects and procs
OLE Automation
MS Add-In Designer
MS Outlook 9.0 Object Library
MS Office 9.0 Object Library
MS CDO 1.21 Object Library
MS Excel 9.0 Object Library
MS PowerPoint 9.0 Object Library
MS Word 9.0 Object Library
MS Windows Installer Object Library

Stepped directly into the ItemsCB code (OnConnection, specifically), which
is configured to start Outlook when debugging.
gBaseClass is not instantiated, Application and AddInInst both appear to
be valid and acceptable objects of Outlook.Application and ItemsCB.Connect
respectively. ItemsCB.Connect appears to be registered with a ClsID of
{48579BE9-DB85-11D2-995E-00A0C96E2838}. ItemsCB.OutAddIn is also registered
with a ClsId of {48579BE7-DB85-11D2-995E-00A0C96E2838}. Outlook.Application
is registered with a ClsId of {0006F03A-0000-0000-C000-000000000046}.
When InitHandler is called, I get a run-time error 8002801d - Library not
registered. I repaired my Office 2000 installation in hopes that this was
the issue, but alas, no luck. ItemsCB.Connect appears to be registered with
a ClsID of {48579BE9-DB85-11D2-995E-00A0C96E2838}. ItemsCB.OutAddIn is also
registered with a ClsId of {48579BE7-DB85-11D2-995E-00A0C96E2838}.
Outlook.Application is registered with a ClsId of
{0006F03A-0000-0000-C000-000000000046}.
 
C

Chris W

Problem solved

With some help I discovered that the root of the issue was my installation of the Office XP PIAs when I was going to use .NET. When we removed the version 9.1 typelib reference, it suddenly worked

Thanks once again for your help, Ken!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top