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

can't access outlook contacts from excel via VBA



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old June 9th 09, 08:04 PM posted to microsoft.public.outlook.program_vba
Mr. Cheeks
external usenet poster
 
Posts: 1
Default can't access outlook contacts from excel via VBA

Hello!

I hope you can help me correctly run this VBA script. I'm trying to run a
script in Excel that will display information from my Outlook contacts. I
tried to follow examples on this site, but I'm running into problems
accessing the contact folder.

I'm running Outlook & Excel 2003, Windows XP, and my work has an exchange
server but I'm not sure how this complicates things.

Thanks so much! Let me know if I can provide any more info.


Sub ShowContactNames ()

Set OutApp = CreateObject("Outlook.Application")
Set myNameSpace = OutApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts) 'It errors out
on this line
Set myContacts = myFolder.Items

For Each myContact In myContacts
MsgBox "Name = " & myContact.FullName
Next

MsgBox "You Rock!"

End Sub

Error out on line "Set myFolder = myNameSpace..."

"Run-Time error '-2147024809 (80070057)': Could not complete the operation.
One or more parameter values are not valid."

Help me MVPs, you're my only hope!
Ads
  #2  
Old June 10th 09, 02:29 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default can't access outlook contacts from excel via VBA

Do you have a reference set in your Excel VBA project for the Outlook object
model?

From outside code it's also advisable to log into the NameSpace after you
retrieve it:

Set myNameSpace = OutApp.GetNamespace("MAPI")
myNameSpace.Logon "", "", False, False


--
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


"Mr. Cheeks" Mr. wrote in message
...
Hello!

I hope you can help me correctly run this VBA script. I'm trying to run a
script in Excel that will display information from my Outlook contacts. I
tried to follow examples on this site, but I'm running into problems
accessing the contact folder.

I'm running Outlook & Excel 2003, Windows XP, and my work has an exchange
server but I'm not sure how this complicates things.

Thanks so much! Let me know if I can provide any more info.


Sub ShowContactNames ()

Set OutApp = CreateObject("Outlook.Application")
Set myNameSpace = OutApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts) 'It errors
out
on this line
Set myContacts = myFolder.Items

For Each myContact In myContacts
MsgBox "Name = " & myContact.FullName
Next

MsgBox "You Rock!"

End Sub

Error out on line "Set myFolder = myNameSpace..."

"Run-Time error '-2147024809 (80070057)': Could not complete the
operation.
One or more parameter values are not valid."

Help me MVPs, you're my only hope!


  #3  
Old June 11th 09, 05:34 PM posted to microsoft.public.outlook.program_vba
Mr. Cheeks[_2_]
external usenet poster
 
Posts: 2
Default can't access outlook contacts from excel via VBA

Ken -- thanks for your help!

I didn't have any luck with the NameSpace logon - the routine still errors
out with the same error message when I call myNameSpace.GetDefaultFolder.
I'm not what you mean when you ask if I have a reference set for the Outlook
object model in my project -- which probably means I don't have it!

Could you direct me to a source for more info? I feel I'm very close to
fixing my routine, and finishing a SWEET macro.

-Cheeks

"Ken Slovak - [MVP - Outlook]" wrote:

Do you have a reference set in your Excel VBA project for the Outlook object
model?

From outside code it's also advisable to log into the NameSpace after you
retrieve it:

Set myNameSpace = OutApp.GetNamespace("MAPI")
myNameSpace.Logon "", "", False, False


--
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


"Mr. Cheeks" Mr. wrote in message
...
Hello!

I hope you can help me correctly run this VBA script. I'm trying to run a
script in Excel that will display information from my Outlook contacts. I
tried to follow examples on this site, but I'm running into problems
accessing the contact folder.

I'm running Outlook & Excel 2003, Windows XP, and my work has an exchange
server but I'm not sure how this complicates things.

Thanks so much! Let me know if I can provide any more info.


Sub ShowContactNames ()

Set OutApp = CreateObject("Outlook.Application")
Set myNameSpace = OutApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderContacts) 'It errors
out
on this line
Set myContacts = myFolder.Items

For Each myContact In myContacts
MsgBox "Name = " & myContact.FullName
Next

MsgBox "You Rock!"

End Sub

Error out on line "Set myFolder = myNameSpace..."

"Run-Time error '-2147024809 (80070057)': Could not complete the
operation.
One or more parameter values are not valid."

Help me MVPs, you're my only hope!



  #4  
Old June 11th 09, 05:38 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default can't access outlook contacts from excel via VBA

In your VBA project select Tools, References and see if Outlook is listed
there.

The best place to find programming samples and information for Outlook is at
www.outlookcode.com, but if you get an error trying to get back a default
folder the code there won't help you, there's a real problem.

--
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


"Mr. Cheeks" wrote in message
...
Ken -- thanks for your help!

I didn't have any luck with the NameSpace logon - the routine still errors
out with the same error message when I call myNameSpace.GetDefaultFolder.
I'm not what you mean when you ask if I have a reference set for the
Outlook
object model in my project -- which probably means I don't have it!

Could you direct me to a source for more info? I feel I'm very close to
fixing my routine, and finishing a SWEET macro.

-Cheeks


  #5  
Old June 11th 09, 05:54 PM posted to microsoft.public.outlook.program_vba
Mr. Cheeks[_2_]
external usenet poster
 
Posts: 2
Default can't access outlook contacts from excel via VBA

OMG UR AHH-SUMM! Turning on the Outlook references did the trick. Thanks!
-Cheeks

"Ken Slovak - [MVP - Outlook]" wrote:

In your VBA project select Tools, References and see if Outlook is listed
there.

The best place to find programming samples and information for Outlook is at
www.outlookcode.com, but if you get an error trying to get back a default
folder the code there won't help you, there's a real problem.

--
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


"Mr. Cheeks" wrote in message
...
Ken -- thanks for your help!

I didn't have any luck with the NameSpace logon - the routine still errors
out with the same error message when I call myNameSpace.GetDefaultFolder.
I'm not what you mean when you ask if I have a reference set for the
Outlook
object model in my project -- which probably means I don't have it!

Could you direct me to a source for more info? I feel I'm very close to
fixing my routine, and finishing a SWEET macro.

-Cheeks



 




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
Access Excel (whether already open or not) from Outlook wpiet Outlook and VBA 2 January 6th 09 08:30 PM
Outlook 2003 IPM.NOTE (Form) Exporting to Access or Excel [email protected] Outlook - Using Forms 0 December 5th 08 02:53 PM
Why can't I export outlook contacts to Excel/Access, etc? Pat Outlook - Using Contacts 2 January 16th 07 11:04 PM
Excel macro to create e-mail in Outlook Web Access fitful_thought Outlook - General Queries 0 April 15th 06 10:23 AM
Can you import contacts from Outlook to Excel, Access, Word &how? ericsayang Outlook - General Queries 1 February 2nd 06 06:39 PM


All times are GMT +1. The time now is 10:27 AM.


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.