2
votes

I have manage to add folders in Outlook, but can't work out how to move them. The code I have does not throw out any warnings and does not move the folder:

#!/usr/bin/perl
use strict;
use warnings;

use Win32::OLE;
use Win32::OLE::Const 'Microsoft Outlook';

# use existing instance if Outlook is already running, or launch a new one
  my $Outlook;
eval {$Outlook = Win32::OLE->GetActiveObject('Outlook.Application')};
die "Outlook not installed" if $@;
unless (defined $Outlook) {
  $Outlook = Win32::OLE->new('Outlook.Application', sub {$_[0]->Quit;})
    or die "Oops, cannot start Outlook";
}
my $namespace = $Outlook->GetNamespace("MAPI");

#my $Folder = $namespace->Folders("backupadmin")->Folders(
    # "Inbox")->Folders->Add("test");

my $Folder = $namespace->Folders("backupadmin")->Folders(
     "Inbox")->Folders("test")->MoveTo("test1");     
1
The Outlook VB namespace looks pretty dicey; is your goal to rename the folder, or re-parent it? If the goal is naming, something like ...->Folders("test")->Name = "test1" may work (or something similar using proper syntax like setName, etc.). Renaming referenceabiessu
More correctly, my $Folder = $namespace->Folders("backupadmin")->Folders("Inbox")->Folders("test")->{"Name"} = "test1"; (again assuming that the intent is to rename the folder, not re-parent it), or ...->Folders("test")->SetProperty('Name', "test1")abiessu
Note that there are other comments out there suggesting that once a rename like this has been applied, there must be a refresh to see the results as well.abiessu

1 Answers

0
votes

If you use the popular Outlook Redemption library, you can retrieve a RDO Folder object for the folder you want to move and then call the MoveTo method with the destination RDO folder as the parameter. For some sample Perl code, you can reference the Email::PST::Win32 CPAN module which uses Win32::OLE and Outlook Redemption to access RDO Folder objects.

Outlook Redemption: http://www.dimastr.com/redemption/home.htm

RDO Folder with MoveTo Method: http://www.dimastr.com/redemption/rdo/rdofolder.htm

Email::PST::Win32: https://metacpan.org/release/Email-PST-Win32