AOB
Registered User.
- Local time
- Today, 09:58
- Joined
- Sep 26, 2012
- Messages
- 621
Hi guys,
I've written a function which opens the Outlook GAL dialog, allows users to select recipients and passes back a 2-D array (recipients and type i.e. To, CC or BCC)
Here is the code :
The only problem I have is that when I 'display' the SelectNamesDialog, it doesn't make it the active window and bring it to the front - it just opens the dialog in Outlook and you have to navigate to the main Outlook window to find it.
I'd like for the dialog to 'popup' - ideally, without the main Outlook window dragging along behind
I believe it's possible (judging from this article) to achieve this using API's - specifically, a combination of FindWindow (to retrieve the window handle) and ShowWindowLong (to set it to a topmost window in front of all other windows)
But I'm not great at these API functions and have really only dabbled briefly in them previously.
Anybody got any suggestions as to how I could do this? These may not even be the best / most appropriate API's, I just saw them in that article and figured they sounded right. But struggling to put them together.
Thanks!
Al
I've written a function which opens the Outlook GAL dialog, allows users to select recipients and passes back a 2-D array (recipients and type i.e. To, CC or BCC)
Here is the code :
Code:
Public Function GetContactsFromOutlookGAL() As Variant
Dim appOutlook As Object ' Outlook Application
Dim objNameSpace As Object ' Outlook NameSpace
Dim objSelectNamesDialog As Object ' Outlook Select Names Dialog
Dim arrRecipients() As Variant
Dim itm As Variant
' Initialise the recipient array
ReDim arrRecipients(1 To 2, 1 To 1)
' Connect to MS Outlook
Set appOutlook = CreateObject("Outlook.Application")
Set objNameSpace = appOutlook.GetNamespace("MAPI")
Set objSelectNamesDialog = objNameSpace.GetSelectNamesDialog
With objSelectNamesDialog
.Caption = "Select recipients"
.ShowOnlyInitialAddressList = True
If .Display Then
For Each itm In .Recipients
' Redimension recipient array
If Not IsEmpty(arrRecipients(1, UBound(arrRecipients, 2))) Then _
ReDim Preserve arrRecipients(1 To 2, 1 To UBound(arrRecipients, 2) + 1)
arrRecipients(1, UBound(arrRecipients, 2)) = itm.Name
arrRecipients(2, UBound(arrRecipients, 2)) = itm.Type
Next itm
End If
End With
Set objSelectNamesDialog = Nothing
Set objNameSpace = Nothing
Set appOutlook = Nothing
GetContactsFromOutlookGAL = arrRecipients
End Function
The only problem I have is that when I 'display' the SelectNamesDialog, it doesn't make it the active window and bring it to the front - it just opens the dialog in Outlook and you have to navigate to the main Outlook window to find it.
I'd like for the dialog to 'popup' - ideally, without the main Outlook window dragging along behind
I believe it's possible (judging from this article) to achieve this using API's - specifically, a combination of FindWindow (to retrieve the window handle) and ShowWindowLong (to set it to a topmost window in front of all other windows)
But I'm not great at these API functions and have really only dabbled briefly in them previously.
Anybody got any suggestions as to how I could do this? These may not even be the best / most appropriate API's, I just saw them in that article and figured they sounded right. But struggling to put them together.
Thanks!
Al