Solved

How do you select a "personal" Outlook folder using vba code

Posted on 2003-11-02
6
3,498 Views
Last Modified: 2010-08-05
OK, I can get the properties of the default  Calendar folder in Outlook using the following code:

   Dim ol As New Outlook.Application
   Dim olns As Outlook.Namespace
   Dim cf As Outlook.MAPIFolder
   Dim c As Outlook.AppointmentItem
   Dim objItems As Outlook.Items
   Dim Prop As Outlook.UserProperty
   Dim k As Integer
   Set olns = ol.GetNamespace("MAPI")
   Set cf = olns.GetDefaultFolder(olFolderCalendar)

If I have a stand-alone  pst file, how would I get access to that file?
 
If this isn't possible, then how would I get access to personal calendar file within Outlook?
This file would be under a personal folder called  PRC, then the subfolder called Calendar and then another
subfolder called  Church.
0
Comment
Question by:Mach1pro
  • 4
6 Comments
 
LVL 17

Expert Comment

by:smozgur
ID: 9668469
'----
Dim ol As New Outlook.Application
Dim olns As Outlook.NameSpace
Dim cf As Outlook.MAPIFolder
Dim cal As Outlook.MAPIFolder
 
  Set olns = ol.GetNamespace("MAPI")
  Set cf = olns.Folders("PRC")
  Set cal = cf.Folders("Calendar")
'----

What you need is cal object.

Suat
0
 
LVL 17

Expert Comment

by:smozgur
ID: 9668540
Okay, to make it easy for you to let you use your own code still:

Dim ol As New Outlook.Application
Dim olns As Outlook.NameSpace
Dim cf As Outlook.MAPIFolder
Dim c As Outlook.AppointmentItem
Dim objItems As Outlook.Items
Dim Prop As Outlook.UserProperty
Dim k As Integer
    Set olns = ol.GetNamespace("MAPI")
    Set cf = olns.Folders("PRC").Folders("Calendar")

Suat
0
 
LVL 17

Accepted Solution

by:
smozgur earned 200 total points
ID: 9668589
Or...

Set cf = olns.Folders("PRC").Folders("Calendar").Folders("Church")

or for this folder structure:

-PRC
--Calendar
----Church
--------OtherOne
------------AnotherOne

Set cf = olns.Folders("PRC").Folders("Calendar").Folders("Churc").Folders("OtherOne").Folders("AnotherOne") '.....

Does this solve your problem or do you need another information ? Please let us know.

Suat
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 6

Author Comment

by:Mach1pro
ID: 9668760
This is great.

I will still offer 200 more points though if someone will show me how to make the connection to a
stand alone pst file.
0
 
LVL 17

Expert Comment

by:smozgur
ID: 9669503
Sorry, I don't know how to read a pst file outside of Outlook. I hope someone else does.

Suat
(Thanks for the grade)
0
 

Expert Comment

by:insideoud
ID: 10047670
This should answer yout question:

Sub ExploreFolders()
    Dim ol As New Outlook.Application
    Dim ns As Outlook.NameSpace
    Dim fds As Outlook.Folders
    Dim fd As Outlook.MAPIFolder

    Set ns = ol.GetNamespace("MAPI")
    'Set a reference to all folders within
    'a personal folder called development
    Set fds = ns.Folders("Development").Folders

    'Loop through all of the folders looking
    'for one named Acme.
    For Each fd In fds
        If fd.Name = "Acme" Then
            Exit For
        End If
    Next

    'Display the name of the parent folder
    MsgBox fd.Parent
End Sub
 
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now