Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 657
  • Last Modified:

FolderPath to access a personal folder

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
kph1
Asked:
kph1
  • 3
  • 2
1 Solution
 
TimCotteeCommented:
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
 
kph1Author Commented:
I keep receiving an error on the following line

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

Kevin
0
 
TimCotteeCommented:
Kevin, it may be because the subject line contains characters that are not valid as a file name, such things as:

/\: etc
0
 
kph1Author Commented:
You were right.  Thank you.

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

Kevin
0
 
TimCotteeCommented:
You can use a replace command:

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

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now