Nice
Oct 19th, 2000, 09:20 AM
Hello,
Anyone ou'there to help me? I'm doin with Outlook and VB..I want to add a Menu to the Standard Outlook Menus and implement a Call-Back function in VB Code to manipulate that menu item....Also I want to know if I use Command Bar object(in Outlook 97..in Outlook 2000 it works), will it support event handling? or how to make it support events? Help me plz
Nice.
Shrog
Nov 29th, 2000, 06:46 AM
You have to create an Addin for outlook. The addin is an ActiveX DLL. You get Outlook to run the addin by entering the following into the registry:
HKEY_CURRENT_USER\Software\Microsoft\Office\Outlook\AddIns\MyDLL.MyClass
"Description"="MyDescription"
"FriendlyName"="MyName"
"LoadBehavior"=dword:00000003
You have to replace MyDLL.MyClass, "MyDescription" and "MyName" with the appropriate values of course.
When Outlook starts, it will start the class of the dll you have specified. In the class itself you can have:
Option Explicit
Option Compare Text
Implements AddInDesignerObjects.IDTExtensibility2
Dim WithEvents mOutlook As Outlook.Application
Dim WithEvents mOutlookInspector As Outlook.Inspector
Dim WithEvents mOutlookExplorer As Outlook.Explorer
Dim WithEvents mExplorerButton As Office.CommandBarButton
Dim WithEvents mInspectorButton As Office.CommandBarButton
Dim WithEvents mOutlookInspectors As Outlook.Inspectors
Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
Set mOutlook = Application
End Sub
Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant)
Dim CommandBarItem As Office.CommandBar
Dim Button As Office.CommandBarControl
Dim FoundBar As Boolean
Dim FoundButton As Boolean
Set mOutlookExplorer = mOutlook.Application.ActiveExplorer
Set mOutlookInspectors = mOutlook.Inspectors
'Find out if the tool bar and button exist
On Error Resume Next
Set CommandBarItem = mOutlookExplorer.CommandBars("MyBar")
If Err.Number = 0 Then
For Each Button In CommandBarItem.Controls
If Button.ID = 1 Then
FoundButton = True
Set mExplorerButton = Button
Exit For
End If
Next Button
FoundBar = True
End If
'create if any items are missing
If FoundBar = False Then
Set CommandBarItem = mOutlookExplorer.CommandBars.Add("MyBar", msoBarTop, , False)
End If
If FoundButton = False Then
Set mExplorerButton = CommandBarItem.Controls.Add(msoControlButton, 1, , , False)
End If
'when I get here I have a toolbar and a button
CommandBarItem.Visible = True
Call Clipboard.SetData(picIcon.Picture, vbCFBitmap)
With mExplorerButton
.PasteFace
.Caption = "MyCaption"
.DescriptionText = "Description"
.ToolTipText = "ToolTipText"
.Style = msoButtonIconAndCaption
End With
End Sub
Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)
End Sub
Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)
End Sub
Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
End Sub
Private Sub mExplorerButton_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
Dim Item As Object
If mOutlookExplorer.Selection.Count = 0 Then
Call MsgBox("You have not selected any items.", vbExclamation)
Exit Sub
End If
For Each Item In mOutlookExplorer.Selection
'Do your stuff
Next Item
End Sub
Private Sub mInspectorButton_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
Msgbox mOutlookInspector.CurrentItem.Subject
'do other stuff with CurrentItem
End Sub
Private Sub mOutlookExplorer_Close()
Dim TempForm as Form
For Each TempForm In Forms
Unload TempForm
Next TempForm
Set mOutlook = Nothing
Set mOutlookInspector = Nothing
Set mOutlookExplorer = Nothing
Set mExplorerButton = Nothing
Set mInspectorButton = Nothing
Set mOutlookInspectors = Nothing
End Sub
Private Sub mOutlookInspector_Close()
On Error Resume Next
Set mOutlookInspector = mOutlook.ActiveInspector
Set mInspectorButton = mOutlookInspector.CommandBars.FindControl(, 1)
End Sub
Private Sub mOutlookInspector_Deactivate()
On Error Resume Next
Set mOutlookInspector = mOutlook.ActiveInspector
Set mInspectorButton = mOutlookInspector.CommandBars.FindControl(, 1)
End Sub
Private Sub mOutlookInspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
Dim CommandBarItem As Office.CommandBar
Dim Button As Office.CommandBarControl
Dim FoundBar As Boolean
Dim FoundButton As Boolean
Set mOutlookInspector = Inspector
'Find out if the tool bar and button exist
On Error Resume Next
Set CommandBarItem = Inspector.CommandBars("MyBar")
If Err.Number = 0 Then
For Each Button In CommandBarItem.Controls
If Button.ID = 1 Then
FoundButton = True
Set mInspectorButton = Button
Exit For
End If
Next Button
FoundBar = True
End If
'create if any items are missing
If FoundBar = False Then
Set CommandBarItem = mOutlookInspector.CommandBars.Add("MyBar", msoBarTop, , False)
End If
If FoundButton = False Then
Set mInspectorButton = CommandBarItem.Controls.Add(msoControlButton, 1, , , False)
End If
'when I get here I have a toolbar and a button
CommandBarItem.Visible = True
Call Clipboard.SetData(picIcon.Picture, vbCFBitmap)
With mInspectorButton
.PasteFace
.Caption = "MyCaption"
.DescriptionText = "Description"
.ToolTipText = "ToolTipText"
.Style = msoButtonIconAndCaption
End With
End Sub
Does this answer your question?
Shrog
JoshT
Nov 29th, 2000, 12:10 PM
This article helped me out - it has the method Shrog posted plus an additional way to do it.
http://support.microsoft.com/support/kb/articles/Q238/2/28.ASP
Josh