Help in Creating Outlook 2002 Com add-in in vb6.0

  • Thread starter Karthick Veerappan
  • Start date
K

Karthick Veerappan

I am assuming, I am in the right forum.

I am trying to create a com add-in for outlook 2002 in vb6.0.
The Add-in will read mails from inbox and will send mails also.
I am adding a function call to the commandbutton. It is not calling the
function.

I have created a new Add-in project in vb6.0
I have added a outlook 11.0 object library reference.
The following files are loaded in my project

Connect.Dsr
--------------------------------------------------------------------
Option Explicit

Public FormDisplayed As Boolean
Public VBInstance As Outlook.Application
Dim mcbMenuCommandBar As Office.CommandBarControl
Dim mfrmAddIn As New frmAddIn
Public WithEvents MenuHandler As CommandBarEvents 'command bar
event handler


Sub Hide()

On Error Resume Next

FormDisplayed = False
mfrmAddIn.Hide

End Sub

Sub Show()

On Error Resume Next

If mfrmAddIn Is Nothing Then
Set mfrmAddIn = New frmAddIn
End If

Set mfrmAddIn.VBInstance = VBInstance
Set mfrmAddIn.Connect = Me
FormDisplayed = True
mfrmAddIn.Show

End Sub

'------------------------------------------------------
'this method adds the Add-In to VB
'------------------------------------------------------
Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal
ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As
Object, custom() As Variant)
On Error GoTo error_handler

'save the vb instance
Set VBInstance = Application

If ConnectMode = ext_cm_External Then
'Used by the wizard toolbar to start this wizard
Me.Show
Else
Set mcbMenuCommandBar = AddToAddInCommandBar("My AddIn")
'sink the event
'Set Me.MenuHandler =
VBInstance.Events.CommandBarEvents(mcbMenuCommandBar)
End If

If ConnectMode = ext_cm_AfterStartup Then
If GetSetting(App.Title, "Settings", "DisplayOnConnect", "0") = "1"
Then
'set this to display the form on connect
Me.Show
End If
End If

Exit Sub

error_handler:

MsgBox Err.Description

End Sub

'------------------------------------------------------
'this method removes the Add-In from VB
'------------------------------------------------------
Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode As
AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
On Error Resume Next

'delete the command bar entry
mcbMenuCommandBar.Delete

'shut down the Add-In
If FormDisplayed Then
SaveSetting App.Title, "Settings", "DisplayOnConnect", "1"
FormDisplayed = False
Else
SaveSetting App.Title, "Settings", "DisplayOnConnect", "0"
End If

Unload mfrmAddIn
Set mfrmAddIn = Nothing

End Sub

Private Sub IDTExtensibility_OnStartupComplete(custom() As Variant)
If GetSetting(App.Title, "Settings", "DisplayOnConnect", "0") = "1" Then
'set this to display the form on connect
Me.Show
End If
End Sub

'this event fires when the menu is clicked in the IDE
Private Sub MenuHandler_Click(ByVal CommandBarControl As Object, handled As
Boolean, CancelDefault As Boolean)
Me.Show
End Sub

Function AddToAddInCommandBar(sCaption As String) As Office.CommandBarControl
Dim cbMenuCommandBar As Office.CommandBarControl 'command bar object
Dim cbMenu As Object

On Error GoTo AddToAddInCommandBarErr

'see if we can find the Add-Ins menu
Set cbMenu = VBInstance.ActiveExplorer.CommandBars.Add("Add-Ins")
If cbMenu Is Nothing Then
'not available so we fail
Exit Function
End If

'add it to the command bar
Set cbMenuCommandBar = cbMenu.Controls.Add(1)
'set the caption
cbMenuCommandBar.Caption = sCaption
cbMenuCommandBar.OnAction= "Test" '*** HERE IS MY QUESTION ****
Set AddToAddInCommandBar = cbMenuCommandBar

Exit Function

AddToAddInCommandBarErr:

End Function

Sub Test()
Msgbox "Test Procedure."
End Sub
--------------------------------------------------------------------

frmAddin.frm
---------------------------------------------------------------------
Public VBInstance As VBIDE.VBE
Public Connect As Connect

Option Explicit

Private Sub CancelButton_Click()
Connect.Hide
End Sub

Private Sub OKButton_Click()
MsgBox "AddIn operation on: " & VBInstance.FullName
End Sub
----------------------------------------------------------------------


*********** My Question **************

cbMenuCommandBar.OnAction= "Test"

The above code is not working. It is not calling the function "Test".
I have tried with various methods like

"Test"
"<Test>"
"!<Test>"

and event i have moved the entire function into a separate module.
but still the above mentioned code is not working.

Am I calling the function in the right place? If wrong please correct me.

Please HELP me In this problem. F1 F1 F1.
 
M

Michael Bauer [MVP - Outlook]

This is not the right group for programming issues. Next time, please use
e.g. *outlook.program_vba

Instead of OnAction, use a variable declared like this on op of the module,
that is above of all of your code:

Private WithEvents MyButton as Office.ComandbarButton

Set the variable to the button you're creating. The declaration must be in a
class module, and that module must not be destroyed. (You can use the
designer module for that.)

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool:
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Thu, 1 May 2008 23:00:00 -0700 schrieb Karthick Veerappan:
 

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