D-man

Adding an Outlook folder to non default data file

22 posts in this topic

Hi,

I am able to add folders and sub folders to my default data file in Outlook using the code below. I also have a second data file (PST) loaded in Outlook. How do I add a sub folder to that location?

Global $oOutlook = _OL_Open()
Global $oFolder = _OL_FolderCreate($oOutlook, "Test Folder 2", $olFolderInbox, "*\Test Folder 1\")
_OL_Close($oOutlook)

 

Thanks in advance!

Share this post


Link to post
Share on other sites



Use _OL_PSTAccess to access the PST and then add the subfolder like you did in your post.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I tried adding the PST access code below, but the folder is still being created in the default data file. Is there a good working example that I could look at to try and figure out what I am missing?

 

Global $oOutlook = _OL_Open()


; Access PST
Global $oFolder = _OL_PSTAccess($oOutlook, "C:\Users\MyUser\Documents\Outlook Files\My Outlook Data File 1.pst")

Global $oFolder = _OL_FolderCreate($oOutlook, "Test Folder 1", $olFolderInbox)

_OL_Close($oOutlook)

Share this post


Link to post
Share on other sites

What is the value of @error after calling _OL_PSTAccess and _OL_FolderCreate?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hi,

I added the error checking lines and don't get any errors. The folder gets successfully created, just not in my PST. Please see code below.

 

Global $oOutlook = _OL_Open()

; Access PST
Global $oFolder = _OL_PSTAccess($oOutlook, "C:\Users\z151947\Documents\Outlook Files\My Outlook Data File 1.pst")
If @error <> 0 Then Exit MsgBox(16, "OutlookEX Example Script", "Error accessing 'My Outlook Data File 1.pst' archive. @error = " & @error & ", @extended: " & @extended)

Global $oFolder = _OL_FolderCreate($oOutlook, "Test Folder 1", $olFolderInbox)
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_FolderCreate Example Script", "Error creating folder 'Test-Folder' in folder 'Outlook-UDF-Test\SourceFolder'. @error = " & @error)

$oFolder.Display
MsgBox(64, "OutlookEX UDF: _OL_FolderCreate Example Script", "Folder successfully created!")

_OL_Close($oOutlook)

Share this post


Link to post
Share on other sites

You need to define the folder in which the new one should be created:

Global $oFolder = _OL_FolderCreate($oOutlook, "Test Folder 1", $olFolderInbox, $oFolder)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I replaced:

Global $oFolder = _OL_FolderCreate($oOutlook, "Test Folder 1", $olFolderInbox)

with:

Global $oFolder = _OL_FolderCreate($oOutlook, "Test Folder 1", $olFolderInbox, $oFolder)

but the results are the same. I wonder if "$olFolderInbox" is the problem. The example I saw was for creating a new task folder, so I took a guess and replaced "$olFolderTasks" with "$olFolderInbox" to create a new email folder in the default data file and it worked.

 

Share this post


Link to post
Share on other sites

So it Looks like that there can only be a single Inbox.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Yes, the inbox is only in my default data file and that's where all my incoming email arrives. I even tried manually adding "Inbox" folder to my PST and run the script, but it didn't work. So, do you think it's just not possible to add a folder to a PST or there is a chance "$olFolderInbox" can be changed to some other value that would work?

Share this post


Link to post
Share on other sites

I will do some tests as soon as I find some spare time. What you need is a folder with default item type of mail?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks for your help! I am not sure I understand the default item type in context of a personal PST data file. Please see attached image of my Outlook folder structure.

Outlook Folder Structure.jpg

Share this post


Link to post
Share on other sites

This works fine for me:

#include <OutlookEX.au3>

Global $oOL = _OL_Open()
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended)

Global $oPST = _OL_PSTAccess($oOL, "C:\temp\My Outlook Data File 1.pst", "Outlook-UDF-PST")
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error accessing 'Outlook-UDF-PST\'. @error = " & @error)

Global $oFolder = _OL_FolderCreate($oOL, "Test-Folder", $olFolderInbox, $oPST)
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating folder 'Test-Folder' in PST. @error = " & @error)
$oFolder.Display
MsgBox(64, "OutlookEX UDF", "Folder 'Test-Folder' (Type: tasks) successfully created in PST.")

_OL_Close($oOL)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Thanks for testing!! Very strange... I tried your code, except for the PST file path, and it still created the new folder in default data file. Interestingly, my default Outlook data file name got changed to "Outlook-UDF-PST" (see attached image), so somehow the PST object access is not working during the folder create.

I also attached the Outlook and Windows versions I am running.

 

Global $oOL = _OL_Open()
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended)

Global $oPST = _OL_PSTAccess($oOL, "C:\Users\MyUser\Documents\Outlook Files\My Outlook Data File 1.pst", "Outlook-UDF-PST")
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error accessing 'Outlook-UDF-PST\'. @error = " & @error)

Global $oFolder = _OL_FolderCreate($oOL, "Test-Folder", $olFolderInbox, $oPST)
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating folder 'Test-Folder' in PST. @error = " & @error)
$oFolder.Display
MsgBox(64, "OutlookEX UDF", "Folder 'Test-Folder' (Type: tasks) successfully created in PST.")

_OL_Close($oOL)

 

Outlook Folder Structure After Script.jpg

 

MS Versions.jpg

Edited by D-man

Share this post


Link to post
Share on other sites

Thanks for testing!! Very strange... I tried your code, except for the PST file path, and it still created the new folder in default data file. Interestingly, my default Outlook data file name got changed to "Outlook-UDF-PST" (see attached image), so somehow the PST object access is not working during the folder create.

What do you mean by "default data file"? Is this an Exchange Mailbox, another PST or ...?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Please see attached image.

Outlook data files.jpg

Share this post


Link to post
Share on other sites

The only difference I see is that your default data file is a OST. Mine is an Exchange server.
Is it possible for you to test with an Exchange mailbox?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I disabled data file caching so Outlook now runs directly from the Exchange Server (see image), but it didn't help.

This is the first time I tried OutlookEX UDF, so the first piece of code I ran was to setup the test environment (see below).

; *****************************************************************************
; Create test environment
; *****************************************************************************
;~ Global $oOutlook = _OL_Open()
;~ If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended)
;~ Global $Result = _OL_TestEnvironmentCreate($oOutlook)
;~ If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF - Manage Test Environment", "Error creating the test environment. @error = " & @error & ", @extended = " & @extended)

; *****************************************************************************

This created some hidden objects in my Outlook. I tried to manually cleanup the test environment by temporary modifying OutlookEX UDF to only run the "; Delete existing folder structure" section of the Func _OL_TestEnvironmentCreate. This seemed to have worked, but I am not sure if there is still residue that I don't know about. I wonder if this is messing up the folder create...

 

Exchange Online Mode Enabled.jpg

Share this post


Link to post
Share on other sites

To delete the test environment simply run _OL_TestEnvironment.au3.

The test environment should not have negative effects on other functions.

From the code you posted I see that you no longer call _OL_Open. This might cause the problem ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

The test environment snippet was from another file. This is my current script.

Global $oOL = _OL_Open()
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended)

Global $oPST = _OL_PSTAccess($oOL, "C:\Users\MyUser\Documents\Outlook Files\My Outlook Data File 1.pst", "Outlook-UDF-PST")
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error accessing 'Outlook-UDF-PST\'. @error = " & @error)

Global $oFolder = _OL_FolderCreate($oOL, "Test-Folder", $olFolderInbox, $oPST)
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating folder 'Test-Folder' in PST. @error = " & @error)
$oFolder.Display
MsgBox(64, "OutlookEX UDF", "Folder 'Test-Folder' (Type: tasks) successfully created in PST.")

_OL_Close($oOL)

 

I couldn't find _OL_TestEnvironment.au3. Do I have the correct UDF version?

 

; #INDEX# =======================================================================================================================
; Title .........: Microsoft Outlook Function Library (MS Outlook 2003 and later)
; AutoIt Version : 3.3.9.2 (New COM error handler), runs with 3.3.8.1 too
; UDF Version ...: 0.10.0.0
; Language ......: English
; Description ...: A collection of functions for accessing and manipulating Microsoft Outlook
; Author(s) .....: wooltown, water
; Modified.......: 20131110 (YYYYMMDD)
; Contributors ..: progandy (CSV functions taken and modified from http://www.autoitscript.com/forum/topic/114406-csv-file-to-multidimensional-array)
;                  Ultima, PsaltyDS for the basis of the __OL_ArrayConcatenate function
; Resources .....: Outlook 2003 Visual Basic Reference: http://msdn.microsoft.com/en-us/library/aa271384(v=office.11).aspx
;                  Outlook 2007 Developer Reference:    http://msdn.microsoft.com/en-us/library/bb177050(v=office.12).aspx
;                  Outlook 2010 Developer Reference:    http://msdn.microsoft.com/en-us/library/ff870432.aspx
;                  Outlook Examples:                    http://www.vboffice.net/sample.html?cmd=list&mnu=2
; =========================================================================================================================

Share this post


Link to post
Share on other sites

Version 0.10 is from 2013-11. Please download the newest version 1.0.0.0 dated 2014-07 and try again.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now