Solved

FolderPath to access a personal folder

Posted on 2002-07-10
5
620 Views
Last Modified: 2009-12-16
I want to open a folder that is in a personal folder (instead of \\outlook\inbox it is \\personal folder\pacc) but cannot seem to be able to point.  My main goal is to open that folder up and save each mailitem in that folder as a .txt file with the subject and the date being the file name.  Do I still use Set fldFolder = nmsName.GetDefaultFolder(olFolderInbox) to access the folder?

My code is starting to look something like:

Sub PACC_Club_Mail()
 
 Dim myItem As Inspector
 Dim objItem As Object

 Set myOlApp = CreateObject("Outlook.Application")
 Set myNamespace = myOlApp.GetNamespace("MAPI")
 Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox)
 Set myItem = myOlApp.ActiveInspector
 
  If Not TypeName(myItem) = "Nothing" Then
      Set objItem = myItem.CurrentItem
      strname = objItem.Subject
      objItem.SaveAs "C:\" & strname & ".txt", olTXT
  Else
      MsgBox "There is no current active Inspector."
  End If

myFolder.Display
Set myNewItem = myFolder.Items(1)
myNewItem.Display

End Sub

Of course this uses ActiveInspector but I want it to automatically go into the folder and perform the saveas without any mailitems opened.

Kevin
0
Comment
Question by:kph1
  • 3
  • 2
5 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 200 total points
ID: 7145440
Dim fdrPACC As MAPIFolder
Dim appOutlook As Outlook.Application
Dim nspMAPI As NameSpace
Set appOutlook = CreateObject("Outlook.Application")
Set nspMAPI = appOutlook.GetNamespace("MAPI")
Set fdrPACC = nspMAPI.Folders("Personal Folders").Folders("pacc")
For i = fdrPACC.Items.Count To 1 Step -1
  Set mtmItem = fdrPACC.Items(i)
  With mtmItem
    .SaveAs "c:\" & .Subject & ".txt",otTXT
  End With
Next
' then destroy objects.
0
 

Author Comment

by:kph1
ID: 7149528
I keep receiving an error on the following line

.SaveAs "c:\" & .Subject & ".txt", olTXT

Kevin
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 7149554
Kevin, it may be because the subject line contains characters that are not valid as a file name, such things as:

/\: etc
0
 

Author Comment

by:kph1
ID: 7149786
You were right.  Thank you.

How could I cycle through each .Subject line and replace the "\/:" characters with spaces?

Kevin
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 7153632
You can use a replace command:

Dim strSubject As String
strSubject = Replace(Replace(Replace(.Subject,"\"," "),"/"," "),":"," ")
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA error replacing data 6 40
VBA/SQL - Connect to SQL server and pull data 4 109
fso.FolderExists("\\server\HiddenFolder$") 4 65
Zip Folders Using Chilkat Routines 1 40
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 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