A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Select Names Dialog Box



 
 
Thread Tools Search this Thread Display Modes
  #11  
Old February 12th 10, 06:40 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Select Names Dialog Box

objSession.Logon , , False, False

That's what's called in CDO as a piggy-back logon, attaching to an existing
Outlook session. It would only work if Outlook is already running. An
alternative of specifying a CDO logon profile is usually not the best idea,
it ends up either leaking or creating profiles in your registry that you
don't really want.

Check for Outlook running and if it's not running then start it to avoid the
problem.

www.cdolive.com is the the Web site for CDO. The tips and tricks pages have
lots of code samples and you can download the CDO.HLP file from there which
explains all the arguments to everything in CDO.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


wrote in message
...
Hi, Ken
I am using the following code that basicly works, other than if outlook
is
closed.
hence what code is required to open outlook if it is closed?
It also looks like .AddressBook has a number of options. Could you list
or
point me to more information on the use of this command.

On Error GoTo err_Session_AddressBook
'MAPI Session
Dim objSession As MAPI.Session
Dim colCDORecips As Object

Set objSession = New MAPI.Session
'objSession.Logon "ProfileName", "outlook", False, False
objSession.Logon , , False, False
'show address book
Set colCDORecips = objSession.AddressBook(, _
"Pick Names", , , 1, _
"Recipients")
' release objects
objSession.Logoff

Set colCDORecips = Nothing
Set objSession = Nothing


err_Session_AddressBook:
If (Err = 91) Then ' MAPI dlg-related function that sets an object
MsgBox "No recipients selected"
Else
'MsgBox "Unrecoverable Error:" & Err
End If

Thank you

Dave


Ads
  #12  
Old February 13th 10, 06:08 PM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 10
Default Select Names Dialog Box

Ken,
I have updated my code as below, it works how I need it to. However could
you have a look at it as I do not full understand you comment on the
objSession.Logon , , False, False.
also I did have a look at the www.cdolive.com site but the sites search
does not work and the copy of the CDO.HLP I can't read at the moment hence
I will have to revisit when I have a bit more time next week.
I take it that if I make a reference to CDO.dll and in my case have an
access database in a folder with the DLL the outlook code I am using will
work on any PC that uses the access programme?


Private Sub Command43_Click()
On Error GoTo err_Session_AddressBook

Dim objOL As Outlook.Application
Dim oOutlook As Object
Dim oMail As Object
Dim objSession As MAPI.Session
Dim colCDORecips As Object

On Error Resume Next
Set objOL = GetObject(, "Outlook.Application")
If Err.Number 0 Then
Set oOutlook = CreateObject("Outlook.Application")
Set oMail = oOutlook.CreateItem(olMailItem)
oMail.Display

End If

Set objSession = New MAPI.Session
objSession.Logon "ProfileName", "outlook", False, False

Set colCDORecips = objSession.AddressBook(, _
"Pick Names", , , 1, _
"Recipients")
' release objects

objSession.Logoff

Set colCDORecips = Nothing
Set objSession = Nothing
Set objOL = Nothing
Set oOutlook = Nothing
Set oMail = Nothing

err_Session_AddressBook:
If (Err = 91) Then ' MAPI dlg-related function that sets an object
MsgBox "No recipients selected"
Else
'MsgBox "Unrecoverable Error:" & Err
End If
End Sub

Thank you for you time and comments.
  #13  
Old February 15th 10, 01:59 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Select Names Dialog Box

If you're starting Outlook, as I recommended, then you should go back to the
original CDO logon, but modified a little:

objSession.Logon "", "", False, False

If you want that code to run on other machines they will need to have CDO
installed on them. You are not allowed to deploy or distribute CDO yourself,
that's illegal. Plus each version of CDO is customized to a specific version
of Outlook.

We also do not recommend deploying Outlook VBA macro code. That's for
personal use or prototyping, not for distribution. For deployment you should
be coding a COM addin.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


wrote in message
...
Ken,
I have updated my code as below, it works how I need it to. However could
you have a look at it as I do not full understand you comment on the
objSession.Logon , , False, False.
also I did have a look at the www.cdolive.com site but the sites search
does not work and the copy of the CDO.HLP I can't read at the moment
hence
I will have to revisit when I have a bit more time next week.
I take it that if I make a reference to CDO.dll and in my case have an
access database in a folder with the DLL the outlook code I am using will
work on any PC that uses the access programme?


Private Sub Command43_Click()
On Error GoTo err_Session_AddressBook

Dim objOL As Outlook.Application
Dim oOutlook As Object
Dim oMail As Object
Dim objSession As MAPI.Session
Dim colCDORecips As Object

On Error Resume Next
Set objOL = GetObject(, "Outlook.Application")
If Err.Number 0 Then
Set oOutlook = CreateObject("Outlook.Application")
Set oMail = oOutlook.CreateItem(olMailItem)
oMail.Display

End If

Set objSession = New MAPI.Session
objSession.Logon "ProfileName", "outlook", False, False

Set colCDORecips = objSession.AddressBook(, _
"Pick Names", , , 1, _
"Recipients")
' release objects

objSession.Logoff

Set colCDORecips = Nothing
Set objSession = Nothing
Set objOL = Nothing
Set oOutlook = Nothing
Set oMail = Nothing

err_Session_AddressBook:
If (Err = 91) Then ' MAPI dlg-related function that sets an object
MsgBox "No recipients selected"
Else
'MsgBox "Unrecoverable Error:" & Err
End If
End Sub

Thank you for you time and comments.


  #14  
Old February 16th 10, 07:55 PM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 10
Default Select Names Dialog Box

Thank you for the updated logon syntax.
All target PC have CDO installed so no problem with DLL now.
One final issue regarding the address book "show names from the".. drop
down.
How do I change the default location via code, eg at the moment its default
is "contacts" should I need its default to be say "outlook address book"
  #15  
Old February 16th 10, 11:19 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Select Names Dialog Box

That's stored in the registry in the profile settings, it's all undocumented
binary and Unicode stuff there. It's something that Outlook reads on startup
only. You can't do much with that with a running session.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


wrote in message
...
Thank you for the updated logon syntax.
All target PC have CDO installed so no problem with DLL now.
One final issue regarding the address book "show names from the".. drop
down.
How do I change the default location via code, eg at the moment its
default
is "contacts" should I need its default to be say "outlook address book"


  #16  
Old February 17th 10, 05:06 PM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 10
Default Select Names Dialog Box

OK, I will call it a day now.
Thank you again for your help
  #17  
Old February 24th 10, 04:52 PM posted to microsoft.public.outlook.program_vba
JP[_3_]
external usenet poster
 
Posts: 201
Default Select Names Dialog Box

Thanks Ken. Some days, it seems like I open my mouth just to switch
feet.

--JP

On Feb 10, 1:21*pm, "Ken Slovak - [MVP - Outlook]"
wrote:
Of course in the old days we used to use CDO.Session.AddressBook() to
display that dialog before the OOM exposed it.

--
Ken Slovak
[MVP - Outlook]http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.http://www.slovaktech.com/products.htm

"JP" wrote in message

...
I don't doubt that you've seen code that displays the address book,
but Outlook doesn't provide any means of doing so prior to Outlook
2007. I have seen (and used) VBA code that manipulates contacts, but
not in the way you want. If you can show otherwise, I'd be glad to see
it.

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook [To] List (aka Select Names) Dialog Master Blaster Outlook - General Queries 2 November 13th 08 08:21 AM
Select Names dialog box shows fax numbers Tara at Walsh Outlook - Using Contacts 1 January 30th 08 08:33 PM
select names dialog box. harkworkinman Outlook - Using Contacts 3 December 6th 06 10:10 AM
Showing the 'Select Names' (recipients) dialog Mr. Smith Outlook and VBA 1 December 1st 06 03:31 PM
Select names dialog box (again) Zoranst Outlook - Using Contacts 5 September 13th 06 10:29 PM


All times are GMT +1. The time now is 07:53 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.