sample

  • Thread starter Thread starter Joel
  • Start date Start date
J

Joel

Custom task form in public folders ....

Does anybody have sample code of how to create a folder and go to the folder in Windows explorer?
 
Assuming you have permissions to create top-level Public Folders, this code
will do what you need (just change the name of the new folder in Folders.Add):

Sub CreateNewPublicFolder()
On Error Resume Next

Dim objNS As Outlook.NameSpace
Dim objAllPF As Outlook.MAPIFolder, objNewFolder As Outlook.MAPIFolder

Set objNS = Application.GetNamespace("MAPI")
Set objAllPF = objNS.GetDefaultFolder(olPublicFoldersAllPublicFolders)

If objAllPF Is Nothing Then
'This shouldn't happen unless Public Folders do not exist at all
MsgBox "Unable to retrieve the default 'All Public Folders' node."
GoTo Leave:
End If

Set objNewFolder = objAllPF.Folders.Add("New Folder")
If objNewFolder Is Nothing Then Exit Sub

Application.ActiveExplorer.SelectFolder (objNewFolder)

Leave:
Set objNewFolder = Nothing
Set objNS = Nothing
Set objAllPF = Nothing
End Sub
 
Eric,

Thank you so much - but I'm trying to create a folder in Windows, not in
outlook. (as if you are in Windows Explorer) Thank you so much for your
help in advance!

-Joel
 
Sorry, I assumed I saw text referring to an "Outlook Explorer" object.

This is an Outlook programming newsgroup, so I suggest you redirect your
question to one of the Windows programming newsgroups.
 
Eric - within my custom outlook form code, I wish to create a folder. e.g.
in my custom form, I press a button, it creates a folder somewhere on my C:/
drive. Does that make sense? I'm pretty sure I'm in the right newsgroup
regarding this question.

Thanks for your help again - Joel

Eric Legault said:
Sorry, I assumed I saw text referring to an "Outlook Explorer" object.

This is an Outlook programming newsgroup, so I suggest you redirect your
question to one of the Windows programming newsgroups.
 
Yes, I see your point. However, the focus of this group is to answer
questions relating to programming with the Outlook Object Model using VBA
(although topics relating to CDO, MAPI, and Exchange Development are
pseudo-relevant).

The easiest way to do what you want is to use the Microsoft Scripting
Runtime Library, which has a FileSystemObject that allows you to interact
with the file system. This code snippet is from the Visual Basic Scripting
help file ("C:\Program Files\Microsoft Office\OFFICE11\1033\VBSCRIP5.CHM"),
which has full documentation for the FileSystemObject.

Function CreateFolderDemo
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateFolder("c:\New Folder")
CreateFolderDemo = f.Path
End Function
 
Eric,

That's exactly what I needed to know. I tried it and it works perfect.
Thanks for your help and hope to deal with you in the future!

-Joel
 
Back
Top