Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write to Outlook Calendar (posted code to write) 1

Status
Not open for further replies.

timgerr

IS-IT--Management
Joined
Jan 22, 2004
Messages
364
Location
US
Ok I need some help, I am trying to write a Outlook conduit that will take Calender information and send them to a database. I then want to be able to connect to a database to add entries to the calendar. How can I write to the calender, I can read from it but not write to it. Any information or examples would help.

FYI here is code for reading from Outlook Calendar:
Code:
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Outlook';
use Digest::MD5 qw(md5_hex);
use DBI;  

# Making a connection to a database
$dbfile = 'U:\\scripts\\Perl\\outlook\\calendar.db';
$dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "",
                    { RaiseError => 1, AutoCommit => 0 });



# Connection to Outlook Calendar	
my $outlook = Win32::OLE->new('Outlook.Application') or die
"Error!\n";

my $namespace = $outlook->GetNamespace("MAPI");
my $folder = $namespace->GetDefaultFolder(olFolderCalendar);
my $CalendarFolderItems = $folder->Items;
print length($folder) . "\n";

for my $itemIndex (1..$CalendarFolderItems->Count)
{
  my $CalendarItem = $CalendarFolderItems->item($itemIndex);
  next if not defined $CalendarItem;

   		$start_date 	= $CalendarItem->{Start}->Date;
   		$start_time 	= $CalendarItem->{Start}->Time;
   		$end_date		= $CalendarItem->{End}->Date;
   		$end_time		= $CalendarItem->{End}->Time;
   		$duration		= $CalendarItem->{Duration};
   		$subject 		= $CalendarItem->{Subject};
   		$categories 	= $CalendarItem->{Categories};
   		$body			= $CalendarItem->{Body};
   		$reminder		= $CalendarItem->{ReminderMinutesBeforeStart};
		# Setting up the MD5 to create a unique identifier
		$md5setup 		= $start_date . $start_time . $end_date . $end_time . $subject . $body . $duration . $reminder;
   		$md5hash 		= md5_hex($md5setup);
   
		
		if ($categories =~ m/Holiday/){
		
		}else{
		
			# searching and replaicing apostraphies
			$subject =~ s/\'/\''/g; 
			$body 	 =~ s/\'/\''/g;
						
			print "*****************************************\n";
			print "Start Date " . $start_date . "\n";
			print "Start Time " . $start_time . "\n";
			print "End Date " 	. $end_date . "\n";
			print "End Time " 	. $end_time . "\n";
			print "Duration " 	. $duration . "\n";
			print "Subject " 	. $subject 		. "\n";
			print "Categories " . $categories 	. "\n";
			print "Body " 		. $body 		. "\n";
			print "Reminder " 	. $reminder 	. "\n";
			print "Hash "		. $md5hash		. "\n";
			
			# prepairing the sql statement
			$sql = "NULL,'$start_date','$start_time','$end_date','$end_time','$duration','$subject','$categories','$body','$reminder','$md5hash'";
			# $sql = $reminder . "," . $body . "," . $categories. "," . $subject. "," . $duration . "," . $end_time . "," . $end_date . "," . $start_time . "," . $start_date . "," .  "," . $hash;
			print $sql . "\n";
			$dbh->do("INSERT INTO calendar VALUES ($sql)");
			$dbh->commit(  );
		
	}
	

}

-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
OK here is what I have, I am getting into some troubles, the script is failing at the last line. I am getting the error "Can't call method "Items" on an undefined value at Untitled11.pl line 9." Not sure what to do here,
Thanks for all the help
nanojack
Code:
use Win32::OLE; use Win32::OLE::Const 'Microsoft Outlook'; # Connection to Outlook Calendar my $outlook = Win32::OLE->new('Outlook.Application') or die "Error!\n"; my $namespace = $outlook->GetNamespace("MAPI"); my $app = $namespace->CreateItem(olAppointmentItem); my $CalendarFolderItems = $app->Items;

-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
sorry here is a better view of the code
Code:
use Win32::OLE; 
use Win32::OLE::Const 'Microsoft Outlook'; 
# Connection to Outlook Calendar 
my $outlook = Win32::OLE->new('Outlook.Application') or die "Error!\n"; 
my $namespace = $outlook->GetNamespace("MAPI"); 
my $app = $namespace->CreateItem(olAppointmentItem); 
my $CalendarFolderItems = $app->Items;

-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
OK I got my answer someware else, here is what I needed.

Code:
use strict;


use Win32::OLE;
use Win32::OLE::Const 'Microsoft Outlook';
# Connection to Outlook Calendar    
my $outlook = Win32::OLE->new('Outlook.Application') or die
"Error!\n";

my $newappt = $outlook->CreateItem(olAppointmentItem);

$newappt->{Subject} = "My Test Appointment";

$newappt->{Start} = "12/20/05 3:50:00 PM";
$newappt->{Duration} = 1 ;  #1 minute
$newappt->{Location} = "Someplace";
$newappt->{Body} = "Test Stuff";
$newappt->{ReminderMinutesBeforeStart} = 1;
$newappt->{BusyStatus} = olFree;
$newappt->Save();

-How important does a person have to be before they are considered assassinated instead of just murdered?
-Need more cow bell!!!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top