Default folder to Public folder when Exporting outlook form data toexcel

C

Cass

I am trying to get a code for exporting data from an outlook form to
default to export a certain folder. I keep getting the Object Could
not be found error. When I try it with my personal folders it work but
when i try it with the public I can't get it to work. Is it set up
wrong for public folder selection? Please help

I get the error on " Set olTest = olFolder.Folders("Test Folder")"
Heres the code...

Sub Auto_Open()
Dim olApp As Outlook.Application
Dim olNamespace As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder
Dim olTest 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("Test Folder")


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"
Cells(1, 6).Value = "Fax Number"
Cells(1, 7).Value = "Alternate Contact 1"
Cells(1, 8).Value = "Alternate Phone Number 1"......
...............
 
B

Brian Tillman

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

Code questions go in the programming group:
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