Malleswar

Hi,

Can any one guide me or provide the link to retrieve Address from outllok address book

Thanks in Advance


Re: Visual Studio Tools for Office API to retrieve Address from outlook address book?

Sue Mosher - Outlook MVP

What exactly are you trying to accomplish, for what version(s) of Outlook The Outlook object model has a Namespace.AddressLists collection that exposes all the address lists that the user sees and their basic contents.



Re: Visual Studio Tools for Office API to retrieve Address from outlook address book?

Malleswar

Hi Mosher,

Thank you for reply and solution. Actually I am adding some options to outlook menu which gives my functionality. Here If they enter the name in my form internally it has to phone number and send to my server.

I have one more question. I want to add some options to the context menus which comes when we click on mails and in address book.

Thanks in advance




Re: Visual Studio Tools for Office API to retrieve Address from outlook address book?

Sue Mosher - Outlook MVP

In versions before Outlook 2007, Outlook does not directly expose the right-click context menu in its CommandBars collection. You will, however, see a new right-click command is when the item selected is using a custom form that includes one or more custom actions. You can also add a custom action without using a custom form, as demonstrated at http://www.outlookcode.com/codedetail.aspx id=526

Richard Kagerer has posted a code sample at http://www.outlookcode.com/codedetail.aspx id=314 that shows how you might trick Outlook into exposing the context menu through Explorer.CommandBars.

The C++ sample add-in at http://www.codeproject.com/atl/outlook2k3addin.asp also shows a technique for working with the context menu.

Outlook 2007 provides Application-level events for the most commonly used context menus.

In none of these cases, however, are context menus in the address book exposed.





Re: Visual Studio Tools for Office API to retrieve Address from outlook address book?

Malleswar

Thank you very much Mosher. But first two links are not getting opened. Can you please check them

Thanks in Advance




Re: Visual Studio Tools for Office API to retrieve Address from outlook address book?

Sue Mosher - Outlook MVP

Links are fine. Must have been a hiccup on the server or somewhere in between.



Re: Visual Studio Tools for Office API to retrieve Address from outlook address book?

Malleswar

Mosher,

Thank you very much for you support. I am facing the following errors when copied the code as it is and run the code. That may be very simple but I am unable to find solution as I am very strange to these type of programming

http://www.outlookcode.com/codedetail.aspx id=526

Name 'olContactItem' is not declared.

Name 'olContact' is not declared.

Name 'olMenu' is not declared.


and from this link http://www.outlookcode.com/codedetail.aspx id=314

Type 'CommandBars' is not defined.

Type 'CommandBarButton' is not defined.

Name 'MsoControlType' is not declared.


I did it in VS2005. Do I need to Import any namespace or am I missing anything in this. Plzzz guide me.

Thanks in Advance






Re: Visual Studio Tools for Office API to retrieve Address from outlook address book?

Sue Mosher - Outlook MVP

The object browser is your friend. If you used it, you'd see that the ol* values are constants from the Outlook object model. CommandBars and CommandBarButton are classes in the Office object model, while MsoControlType is an Office enumeration. Therefore, you need to import the Outlook and Office namespaces.





Re: Visual Studio Tools for Office API to retrieve Address from outlook address book?

Malleswar

Hi Sue Mosher,

I am really very much thank ful to you for ur very patient replies. I could work with the code with out any problem. but i dint find any option in any context menu. I have pasted that code as it is, in my VSTO (VS 2005 IDE) plug in.

Can you please guide me

Thanks in Advance




Re: Visual Studio Tools for Office API to retrieve Address from outlook address book?

Sue Mosher - Outlook MVP

In versions before Outlook 2007, Outlook does not directly expose the right-click context menu in its CommandBars collection. You will, however, see a new right-click command is when the item selected is using a custom form that includes one or more custom actions. You can also add a custom action without using a custom form, as demonstrated at http://www.outlookcode.com/codedetail.aspx id=526

Richard Kagerer has posted a code sample at http://www.outlookcode.com/codedetail.aspx id=314 that shows how you might trick Outlook into exposing the context menu through Explorer.CommandBars.

The C++ sample add-in at http://www.codeproject.com/atl/outlook2k3addin.asp also shows a technique for working with the context menu.

Outlook 2007 provides Application-level events for the most commonly used context menus.





Re: Visual Studio Tools for Office API to retrieve Address from outlook address book?

Malleswar

Hi Mosher,

I have checked, in Outlook 2003(SP1). but i dint find the option any in context menu. I am pasting the code here. I am just running the code from VS2005 IDE. It opens Outlook 2003. but after wards i dint find any option in context menu.
Code Snippet


public class ThisAddIn

Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup

End Sub

Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown

End Sub

'Option Explicit

'CommandBars object of Active Explorer. Note we really should
'set this object whenever the active explorer window changes, but
'that's not done in this example.
Dim WithEvents ActiveExplorerCBars As Microsoft.Office.Core.CommandBars
Dim WithEvents ContextButton As Microsoft.Office.Core.CommandBarButton
'Dim WithEvents CBBAbout As CommandBarButton

'A flag, so we don't respond to our own changes in OnUpdate
Private IgnoreCommandbarsChanges As Boolean

'Run this first
Public Sub Install()
ActiveExplorerCBars = Application.ActiveExplorer().CommandBars
End Sub

Private Sub ContextButton_Click(ByVal Ctrl As Office.CommandBarButton, ByVal CancelDefault As Boolean)
MsgBox("You clicked " & Ctrl.Caption)
End Sub

'This fires when the user right-clicks a contact, and also for a lot of other things!
Private Sub ActiveExplorerCBars_OnUpdate()
Dim bar As Microsoft.Office.Core.CommandBar

If IgnoreCommandbarsChanges Then Exit Sub

'Try for the context menu
On Error Resume Next
bar = ActiveExplorerCBars.Item("Malleswar")
On Error GoTo 0

If Not bar Is Nothing Then
AddContextButton(bar)
End If
End Sub

Private Sub AddContextButton(ByVal ContextMenu As Microsoft.Office.Core.CommandBar)
Dim b As Microsoft.Office.Core.CommandBarButton
Dim Control As Microsoft.Office.Core.CommandBarControl

'User cannot play with the Context Menu, so we know there is at most
'only one copy of the control there
Control = ContextMenu.FindControl(Type:=Microsoft.Office.Core.MsoControlType.msoControlButton, Tag:="Test Button")

If Control Is Nothing Then

'Unprotect context menu
ChangingBar(ContextMenu, Restore:=False)

'Create the control
Control = ContextMenu.Controls.Add(Type:=Microsoft.Office.Core.MsoControlType.msoControlButton)

'Set up control
Control.Tag = "Test Button"
Control.Caption = "Test Button"
Control.Priority = 1
Control.Visible = True

'Reprotect context menu
ChangingBar(ContextMenu, Restore:=True)

'Hook the Click event
ContextButton = Control

Else
'Note that Outlook has a bad habbit of changing our Context Menu buttons
'to be priority dropped.
Control.Priority = 1
End If

End Sub

'Called once to prepare for changes to the command bar, then again with
'Restore = true once changes are complete.
Private Sub ChangingBar(ByVal bar As Microsoft.Office.Core.CommandBar, ByVal Restore As Boolean)

Static oldProtectFromCustomize, oldIgnore As Boolean

If Restore Then

'Restore the Ignore Changes flag
IgnoreCommandbarsChanges = oldIgnore

'Restore the protect-against-customization bit
If oldProtectFromCustomize Then bar.Protection = _
bar.Protection And Microsoft.Office.Core.MsoBarProtection.msoBarNoCustomize

Else

'Store the old Ignore Changes flag
oldIgnore = IgnoreCommandbarsChanges
IgnoreCommandbarsChanges = True

'Store old protect-against-customization bit setting then clear
'CAUTION: Be careful not to alter the property if there is no need,
'as changing the Protection will cause any visible CommandBarPopup
'to disappear unless it is the popup we are altering.
oldProtectFromCustomize = bar.Protection And Microsoft.Office.Core.MsoBarProtection.msoBarNoCustomize
If oldProtectFromCustomize Then bar.Protection = bar.Protection _
And Not Microsoft.Office.Core.MsoBarProtection.msoBarNoCustomize

End If

End Sub


End class


anything wrong in this code. Please guide me.

Thanks in Advance,




Re: Visual Studio Tools for Office API to retrieve Address from outlook address book?

Sue Mosher - Outlook MVP

Richard Kagerer's technique, which appears to be what you've used, is a hack, since Outlook 2003 doesn't directly expose its context menu. There's no guarantee that it will work. You might post a comment on his original sample, in case he has any additional insights to offer.



Re: Visual Studio Tools for Office API to retrieve Address from outlook address book?

Malleswar

Hi Mosher,

In that case can you please give me any other solution to add context menu options for both mailing list and contact list Atleast any third pary tool or API or component.

Thanks in advance,






Re: Visual Studio Tools for Office API to retrieve Address from outlook address book?

Sue Mosher - Outlook MVP

Sorry, but I know of no .NET-compatible, supported method for versions before Outlook 2007. The custom action technique that I mentiond earlier probably comes closest to being supportable, but it is definitely not recommended for use with messages.