Exporting from Outlook to Excel Folder Problem

C

Cass

I am trying to get a code for exporting data from an custom outlook
form to
default to export to a certain folder.
I keep getting the message " The Selected Folder Do Not Contain
Contacts" but I know for a fact I have 82 contacts in the folder
Public Folders\All Public Folder\Test. So what am i doing wrong?

Heres the code:


Option Explicit
Sub Auto_Open()


Dim olApp As Outlook.Application
Dim olNamespace As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder
Dim olTest As Outlook.MAPIFolder
Dim olTest2 As Outlook.MAPIFolder
Dim olColItems As Outlook.Items
Dim olItem As Object
Dim strDummy As String
Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim i As Long

Application.ScreenUpdating = False

'Instantiate the MS Outlook objects.
Set olApp = Outlook.Application
Set olNamespace = olApp.GetNamespace("MAPI")
Set olFolder = olNamespace.Folders("Public Folders")
Set olTest = olFolder.Folders("All Public Folders")
Set olTest2 = olTest.Folders("Test")


If olFolder Is Nothing Then
GoTo ExitSub
ElseIf olFolder.DefaultItemType <> olContactItem Then
MsgBox "The selected folder does not contain contacts.",
vbOKOnly
GoTo ExitSub
ElseIf olFolder.Items.Count = 0 Then
MsgBox "No contacts to import.", vbOKOnly
GoTo ExitSub
End If

Set wbBook = ThisWorkbook
Set wsSheet = wbBook.Worksheets(1)

'Prepare the targeting worksheet.
With wsSheet
.Range("A1").CurrentRegion.Clear
Cells(1, 1).Value = "Utility"
Cells(1, 2).Value = "City, State & Zip"
Cells(1, 3).Value = "Main Contact"
Cells(1, 4).Value = "Main Phone Number"
Cells(1, 5).Value = "Email Address"

With Range("A1:EV1")
.Font.Bold = True
.Font.ColorIndex = 30
.Font.Size = 11
End With
End With

Set olColItems = olFolder.Items

'Iterate the collection of contact items.
i = 2
For Each olItem In olColItems
If TypeName(olItem) = "ContactItem" Then
With olItem

If InStr(olItem.FileAs, strDummy) > 0 Then
Cells(i, 1).Value = .FullName
Cells(i, 2).Value = .UserProperties("CityStateZip")
Cells(i, 3).Value = .UserProperties("MainContact")
Cells(i, 4).Value = .PrimaryTelephoneNumber
Cells(i, 5).Value = .Email1Address



Else
Cells(i, 1).Value = .FullName
Cells(i, 2).Value = .HomeAddressStreet
Cells(i, 3).Value = .HomeAddressPostalCode
Cells(i, 4).Value = .HomeAddressCity
Cells(i, 5).Value = .FullName
Cells(i, 6).Value = .Email1Address



End If


End With
i = i + 1
End If






Next olItem


With wsSheet
'Sort the list.
.Range("A2", Cells(2, 6).End(xlDown)).Sort Key1:=Range("A2"), _
Order1:=xlAscending
.Range("A:EV").EntireColumn.AutoFit
End With




Application.ScreenUpdating = True

MsgBox "The list has successfully been updated!", vbInformation

ExitSub:
Set olItem = Nothing
Set olColItems = Nothing
Set olFolder = Nothing
Set olNamespace = Nothing
Set olApp = Nothing
End Sub
 
B

Brian Tillman

Cass said:
I am trying to get a code for exporting data from an custom outlook
form to default to export to a certain folder.

No need to post more than once.
 
C

Cass

No need to post more than once.

I didn't post more than once. Though the first one had similar code it
was actually different and I figured out a little more so I removed
that and posted this. Thanks sir...

Does anyone have any advice?
 
C

Cass

Only to ask in the correct newsgroup.

How about you give constructive advice and direct me to the correct
newsgroup that you would like me to post in & stop being unkind,
otherwise i'm looking for advice with my problem from people who want
to help. Thanks.
 
C

Cass

I already did, in your first thread.

Well that's no help to me considering I deleted the thread almost
immediately and now i'm in THIS thread... Don't know how you're seeing
that thread but you're definately not helping me in this one...
 
B

Brian Tillman

Cass said:
Well that's no help to me considering I deleted the thread almost
immediately and now i'm in THIS thread... Don't know how you're seeing
that thread but you're definately not helping me in this one...

Threads don't get deleted. Your thread is still there. You appear to be
using Google Groups. Google Groups should be able to find it easily.

At any rate, what I said was:

Code questions go in the programming group:
microsoft.public.outlook.program_vba
 
C

Cass

Threads don't get deleted.  Your thread is still there.  You appear tobe
using Google Groups.  Google Groups should be able to find it easily.

At any rate, what I said was:

Code questions go in the programming group:
microsoft.public.outlook.program_vba

What is the link to the other source where I can access these
newsgroups?
 
B

Brian Tillman

Cass said:
What is the link to the other source where I can access these
newsgroups?

Link to it the same way you're linking to this one, except use the other
group's name instead of "microsoft.public.outlook".
 
C

Cass

Link to it the same way you're linking to this one, except use the other
group's name instead of "microsoft.public.outlook".

No I got that... what I mean is how do I get to the other source of
accessing these groups. You said I was using Google Groups. What else
could I be using?
 
U

Uncle Grumpy

Cass said:
No I got that... what I mean is how do I get to the other source of
accessing these groups. You said I was using Google Groups. What else
could I be using?

Outlook Express
Forte Agent

And a host of other news readers.
 
B

Brian Tillman

Uncle Grumpy said:
Outlook Express
Forte Agent

And a host of other news readers.

As well as Microsoft's web interface (although I wouldn't use it myself).

Cass, if you have a newsreader configured, try this link:
news://msnews.microsoft.com/microsoft.public.outlook.program_vba
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top