can't access outlook contacts from excel via VBA

Status
Not open for further replies.
M

Mr. Cheeks

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

Ken Slovak - [MVP - Outlook]

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

"Mr. Cheeks" <Mr. Cheeks> wrote in message

news:838B3A99-C68C-4662-BE06-BE40895A32DB@microsoft.com...
> 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!
 
M

Mr. Cheeks

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

> >

>

> "Mr. Cheeks" <Mr. Cheeks> wrote in message
> news:838B3A99-C68C-4662-BE06-BE40895A32DB@microsoft.com...
> > 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!


>
 
K

Ken Slovak - [MVP - Outlook]

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.

"Mr. Cheeks" <MrCheeks> wrote in message

news:109B0AAA-43EB-4489-8C9C-17109C6B113C@microsoft.com...
> 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
 
M

Mr. Cheeks

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

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

> >

>

> "Mr. Cheeks" <MrCheeks> wrote in message
> news:109B0AAA-43EB-4489-8C9C-17109C6B113C@microsoft.com...
> > 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


>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
M Access replicated Outlook (email folders, calendar, contacts, notes) via web Using Outlook 1
M open outlook contacts in access 2007 form Using Outlook 1
G Linking Outlook to Access for Contacts in Access Outlook VBA and Custom Forms 3
R Adding contacts to Outlook from Access DB Outlook VBA and Custom Forms 1
G How to add a folder shortcut to outlook quick access toolbar? Using Outlook 6
T Render Outlook emails in MS access as they appear in Outlook Outlook VBA and Custom Forms 2
T Outlook "A program is trying to access Outlook" Using Outlook 3
R How can I access my emails from corrupt offline files of MS Outlook ? Using Outlook 1
J Open an outlook email by Subject on MS Access linked table with VBA Outlook VBA and Custom Forms 10
O Synchronize safe persons Outlook 2016 -> Outlook Web Access (OWA) Using Outlook 30
K How to access emails found to be located in "Top of Outlook data file"? Using Outlook 3
O Outlook Web Access - how to disable spam filter Using Outlook 6
F Outlook 2016 bulk email from access Outlook VBA and Custom Forms 3
G Can't open .pst. Message could not access default folder (Outlook 2010 (.pst). Before that was backi Using Outlook 0
D Creating an outlook session from Access vba but run silently. With A specific profile Outlook VBA and Custom Forms 1
T Cannot access outlook.com accounts in Outlook 2016 Using Outlook 1
B Can't expose sender email address when linking outlook to access Using Outlook 3
Diane Poremsky Change Outlook's Programmatic Access Options Using Outlook 0
G Adding a contact to Outlook with a custom form using Access VBA Outlook VBA and Custom Forms 1
C Merging Word and Access into Outlook Using Outlook 4
I Outlook 2016 and Slow access to Outlook.com IMAP Using Outlook 0
B No permission to access Outlook.pst file Using Outlook 1
Norbert VBA Flag that would indicate the email was sent from Outlook to Access. Outlook VBA and Custom Forms 2
U Cannot access fields at bottom of Outlook 2013 Contact Rec. Using Outlook 1
A Synchronize Access Table with Outlook Calendar Appointments Outlook VBA and Custom Forms 3
L Outlook Data Files command not working in the quick access bar Using Outlook 1
Hudas Hyperlink Saved Outlook Email to MS Access Table Using Outlook 4
Hudas Import Outlook Emails(Inbox) to MS Access as Attachment Using Outlook 1
M How do I access a contact list subfolder in Outlook 2013? Using Outlook 5
K how to Access Outlook Contact Properties Using Outlook 1
M Outlook client macro to web access Using Outlook 1
R Limiting Outlook Access to Inside Network Only Exchange Server Administration 1
J Outlook and owa access Using Outlook 1
O Can't create new email or access email acounts Outlook 2003 Using Outlook 1
C MAPI to access a 64 bit Outlook from a 32 bit application; or access via ODBC Using Outlook 0
C Synchronize outlook with access Using Outlook 1
A Allow Programmatic Access Outlook 2010 Using Outlook 3
M open outlook calendar from an access form Using Outlook 4
J Unable to access public folders in Outlook 2007 on Exchange 2010. OWA PF works fine Using Outlook 7
R Proof Of Looping Bug in Reading Outlook Inbox From Access? Outlook VBA and Custom Forms 2
R Access Program Only Looping Part Way Through Outlook Inbox Outlook VBA and Custom Forms 2
H Exporting Outlook Forms to Access or Excel Outlook VBA and Custom Forms 2
P Access - Outlook Outlook VBA and Custom Forms 2
E Redemption access AppointmentItem Label from outlook Outlook VBA and Custom Forms 6
R Outlook and Access integration using VBA Outlook VBA and Custom Forms 1
K Outlook admin vs individual access (VBA pulling info) Outlook VBA and Custom Forms 1
S Sending Email from Access 2007 through Outlook 2007 using template Outlook VBA and Custom Forms 13
D Outlook 2003 - A program is trying to access e-mail addresses Outlook VBA and Custom Forms 5
R Programming Web Outlook Access Outlook VBA and Custom Forms 3
D "Outlook has blocked access to this form template file. Outlook VBA and Custom Forms 3

Similar threads

Top