How to check if folder exists in Outlook, create it if not exists... Via vba for excel. Tks.
But use code also if outlook not is just opened from user.
Check if in principal root of outlook...
-
- PlatinumLounger
- Posts: 4417
- Joined: 26 Apr 2010, 17:36
-
- Administrator
- Posts: 78857
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Chek if in pricipal root of outlook...
Do you want to create a folder immediately below the user's mailbox?
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4417
- Joined: 26 Apr 2010, 17:36
Re: Chek if in pricipal root of outlook...
Yes, you undestand me, as usualHansV wrote:Do you want to create a folder immediately below the user's mailbox?
![Laugh :laugh:](./images/smilies/laugh.gif)
-
- Administrator
- Posts: 78857
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Check if in pricipal root of outlook...
Try this macro:
The code uses late binding, you don't have to set a reference to the Outlook object library.
Code: Select all
Sub CheckOutlookFolder()
Const strFolder = "Sal21" ' change as needed
Dim olApp As Object
Dim olNsp As Object
Dim olTop As Object
Dim olFld As Object
Set olApp = CreateObject(Class:="Outlook.Application")
Set olNsp = olApp.GetNamespace("MAPI")
Set olTop = olNsp.GetDefaultFolder(6).Parent ' 6 = olFolderInbox
On Error Resume Next
Set olFld = olTop.Folders(strFolder)
On Error GoTo 0
If olFld Is Nothing Then
Set olFld = olTop.Folders.Add(strFolder)
End If
' Optional: quit Outlook
olApp.Quit
End Sub
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4417
- Joined: 26 Apr 2010, 17:36
Re: Check if in pricipal root of outlook...
tks!HansV wrote:Try this macro:
The code uses late binding, you don't have to set a reference to the Outlook object library.Code: Select all
Sub CheckOutlookFolder() Const strFolder = "Sal21" ' change as needed Dim olApp As Object Dim olNsp As Object Dim olTop As Object Dim olFld As Object Set olApp = CreateObject(Class:="Outlook.Application") Set olNsp = olApp.GetNamespace("MAPI") Set olTop = olNsp.GetDefaultFolder(6).Parent ' 6 = olFolderInbox On Error Resume Next Set olFld = olTop.Folders(strFolder) On Error GoTo 0 If olFld Is Nothing Then Set olFld = olTop.Folders.Add(strFolder) End If ' Optional: quit Outlook olApp.Quit End Sub
wowrk perfect!