Solved

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

Posted on 2003-11-02
6
3,504 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:Suat Ozgur
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:Suat Ozgur
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:
Suat Ozgur 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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:Suat Ozgur
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

816 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

11 Experts available now in Live!

Get 1:1 Help Now